Timeline

Survey Baby Monkey

baby-monkey-fxhp

Automatic event hangout with cron

Create an online only, hangout event

Create a new event with a date far into the future, like the year 2015. Go to the event’s options > advanced and enable ‘this event is online only’ which will create a unique Hangout URI.

Create a cronjob

Create a cronjob on each device to open the web browser Monday-Friday at 12:49pm and open the unique Hangout URI.

Firefox cron example:

# Run Firefox at 12:49 EST each weekday and open hangout URI
49 12 * * 1-5 export DISPLAY=:0 && /usr/bin/firefox 'hangout-uri'

Chromium-browser cron example:

# Run Chromium-browser at 12:49 EST each weekday and open hangout URI
49 12 * * 1-5 export DISPLAY=:0 && /usr/bin/chromium-browser 'hangout-uri'

Guido name dropped tornado python tulip and pep-3156

Pycon 2013 was excellent, in fact it was my first one I have attended.

I found it odd that django and Pyramid had plenty of talks but nobody mentioned tornado.

The only person that brought up tornado was Guido himself, who has been researching and developing async python since December 12th, 2012. Guido wants to add async API libraries to python core, and has been comparing his work to twisted and more importantly tornado. He is leveraging the existing solutions to stay on the correct track.

Async API’s in Python core! This news was extra exciting for me, because I have already learned the power of async by messing around with tornado. Since the talk many people have approached me and asked for more information about async API’s.

My favorite use for async is long polling for web applications. Here is a diagram that shows how great tornado is:

2013-03-22-tornado-callback-long-polling-event-loop-scaled

This type of polling can support thousands of concurrent users, all connected and waiting for a callback event to occur. I used tornado to build four2go, a real-time and multi-player browser-based-game.

virt-back’s Domfetcher class returns doms from libvirt API

This entry is part 4 of 4 in the series Virt-back
2013-03-02-scale-virt-back-domfetcher-scaled

I’m hooked…

I attended SCaLE 11x, my first technical conference, and had an amazing time. My favorite talk was Michael Day’s “Advancements with Open Virtualization & KVM” (link to slides). Michael’s presentation inspired me to continue my work on virt-back.

During my trip home I used the in-flight wifi to push this commit into the cloud from the clouds! This particular commit re-factored the dom object list generation into a simple-to-use class called Domfetcher. Domfetcher abstracts the libvirt API and grants access to the following helper methods:

get_all_doms( )
Return a list of all dom objects

get_doms_by_names( guest_names=[] )
Accept a list of guest_names, return a list of related dom objects

get_running_doms( )
Return a list of running dom objects

get_shutoff_doms( )
Return a list of shutoff but defined dom objects

This is an example of how to use Domfetcher:

import virtback

# optionally supply hypervisor uri
domfetcher = virtback.Domfetcher()

doms = domfetcher.get_running_doms()

for dom in doms:
    print dom.name()

for dom in doms:
    print dom.info()

for dom in doms:
    print dom.shutdown()

As always thanks for reading!

how to overload default function arguments in python using lambda

Python Lambda functions are very powerful but I often forget how they work or the fun things they do. This post will document how to use a lambda to provide different default arguments to a function.

We will use the human function found in ago.py as an example – because I’m the module author and I really like it. Lets use the interactive python interpreter to run help on the human function.

>>> from ago import human
>>> help( human )

Help on function human in module ago:

human(dt, precision=2, past_tense='{} ago', future_tense='in {}')
    Accept a datetime or timedelta, return a human readable delta string

Shown above the human function accepts 1 argument and 3 named keyword arguments. The dt argument must be a datetime or timedelta object, the precision must be an integer, and the other two must be strings. If we didn’t like the default arguments, we would need to specify (or pass in) new values each time we invoked the function. Example: human(dt, 3, 'this happened {} ago!', 'in {} from now!'). If we know we will always want different default arguments we can create a lambda function to shorten the invocation length.

>> h = lambda dt : human(dt, 3, 'this happened {} ago!', 'in {} from now!')
>>> print h( dt ) # h is much shorter then human, and still reusable!

Above creates a new function h who only accepts one argument dt. This function calls human with our default arguments. This lambda is equivalent to this regular python function:

>>> def h( dt ):
...    return human(d, 3, 'this happened {} ago!', 'in {} from now!')
>>> print h( dt ) # h is much shorter then human, and still reusable!

Here is a working example to show the new lambda function h in action:

>>> from datetime import datetime
>>> from datetime import timedelta
>>> from ago import human
>>> 
>>> h = lambda dt : human(dt, 3, 'this happened {} ago!', 'in {} from now!')
>>> 
>>> present = datetime.now()
>>> 
>>> for i in range( 1, 15 ):
...     if i % 2 == 0:
...         new_date = present - timedelta( i, i * i, i * i * i )
...     else:
...         new_date = present + timedelta( i, i * i, i * i * i )
...     h( new_date )
... 
'in 22 hours, 9 minutes, 30 seconds from now!'
'this happened 2 days, 1 hour, 50 minutes ago!'
'in 2 days, 22 hours, 9 minutes from now!'
'this happened 4 days, 1 hour, 50 minutes ago!'
'in 4 days, 22 hours, 9 minutes from now!'
'this happened 6 days, 1 hour, 51 minutes ago!'
'in 6 days, 22 hours, 10 minutes from now!'
'this happened 8 days, 1 hour, 51 minutes ago!'
'in 8 days, 22 hours, 10 minutes from now!'
'this happened 10 days, 1 hour, 52 minutes ago!'
'in 10 days, 22 hours, 11 minutes from now!'
'this happened 12 days, 1 hour, 52 minutes ago!'
'in 12 days, 22 hours, 12 minutes from now!'
'this happened 14 days, 1 hour, 53 minutes ago!'

Medbox a real life Bioshock and Borderlands medical vending machine

Dr. Zed – come get your fix today!

Medicine Dispensing Systems plans to release MedBox (not to be confused with RedBox) a medical dispenser not unlike those found in video games. Even more controversial MDS plans to vend medical cannabis. My only suggestion to this hilarious idea? Pair the MedBox with the CVS drive-thru pharmacy.


borderlands-medbox




bioshock-health-medbox




bioshock-medbox




medbox-borderlands-bioshock

ago.py human readable timedelta 0.0.4 release


We have released ago.py 0.0.4

pypi: http://pypi.python.org/pypi/ago
repo: https://bitbucket.org/russellballestrini/ago

Special thanks to David Beitey for supplying ideas and python code for this update!

All changes are backward compatible.

Change log:
  • added support for future dates
  • added optional past_tense keyword argument string for custom output
  • added optional future_tense keyword argument string for custom output
  • added 13 tests to help prevent regressions
  • Updated the README.rst documentation for better coverage

We were just shy of 800 downloads on pypi for ago-0.0.3, I hope ago-0.0.4 will perform even better!

Tips for getting pull requests approved

Pull rejection sucks!

You have just coded, implemented, and submitted a pull request. A short while later the request is declined by an upstream maintainer and you feel crushed. We have all been there. Today I’m going to show you a better way. This article will teach you how to create pull requests that get approved.

Chuck Norris always has his pull requests merged upstream
– Russell Ballestrini

Start small

You need to earn trust with the maintainers. Your first commit should be a small change which they cannot reject. Try to write a missing test or re-factor duplicate code. Correct a comment’s accuracy or rename a variable to better reflect its purpose. Your first pull request should not alter how the program works.

start-small.xcf

Don’t add leading or trailing white space

Additional whitespace will alter the diff output. This causes version control systems to flag lines as changed which is irritating and sometimes misleading.

spot-the-diff.xcf

Less is more

Minimize the number of changes to accomplish your goal. People are busy and at times lazy. Reduce the work the maintainers must do to perform a merge. Lowering the amount of lines to review should increase the chance of approval.

less-is-more.xcf

Only commit working code

Do not break the program, only commit working code. If the project has tests make sure they work before you commit.

commit-working-code.xcf

Follow the leader

Try to mimic the maintainers. Follow the coding style and project layout even if it seems wrong. This is not your playground yet. Before you commit, review the VCS logs to learn how verbose or terse your commit messages should be. When in Rome do as the romans do. This silly game of follow the leader reduces friction of an outsider committing to the project.

follow-the-leader.xcf

Comments, docs, and tests oh my!

Your first pull request should clarify or add to the existing documentation. Fix the README, adjust a comment, or write a test. These tasks might appear small but they serve to prove that you possess comprehension of the source code. They also do not alter the program’s functionality. Having a few of these pull requests under-your-belt will earn you trust which will eventuality translate to more responsibly in the future. You will also differentiate yourself from the rest because most people do not enjoy working on documentation.

comments-docs-tests-oh-my.xcf

Blog about the change

Write about the change, give reasons and examples. Include a link to your blog post in the pull request.

ideas-blog-get-heard.xcf

Pull requests are like paragraphs

If you were writing an essay, you would split up your ideas into separate paragraphs. A pull request has many qualities similar to a paragraph. Each commit should be related to the pull request’s main objective. Commits of a pull request should stay focused and on topic.

A pull request is to a program as a paragraph is to an essay.
A commit is to a pull request as a sentence is to a paragraph.

In an essay, if you have more then one topic you should have more then one paragraph. Likewise when coding, only one idea or change per pull request.

Separating your ideas into different pull requests will grant the maintainers greater flexibility when they begin to integrate. They will have the ability to pick-and-choose which requests to merge and everybody wins!

pull-request-stay-focused.xcf

Holiday postal receipt virus

I have attached a link to the questionable file on the bottom of this post. Be careful.

Neither ClamAV nor Avast detected a virus. (phxf-virus-1)

My wife found this in her inbox. I used to develop spam signatures at my previous job so as a habit I asked her the things that tipped her off that something wasn’t kosher. She came up with a list of indicators:

  • There was a mismatch between the date listed and the day of the week. For example it was dated Monday, 2 December 2012, 11:23 AM which was a Sunday
  • The email came from ‘Priority Shipping Service ‘ which did not seem to be associated with Fedex
  • Fedex always leaves a door slip when you miss a delivery
  • The language in the email did not seem to come form a native English speaker
  • We also were not expecting any packages
  • The email greeted “Dear customer” instead of her name

Here is a screenshot of the email with link to the payload:

WARNING The FILE BELOW MAY DAMAGE YOUR COMPUTER

(view the source of this page for a link to the file)

WARNING The FILE ABOVE MAY DAMAGE YOUR COMPUTER

Symantec buys advertising with virt-back keyword

This entry is part 3 of 4 in the series Virt-back

You know you are doing something right when a big company like Symantec purchases advertising using your software’s name, virt-back as a keyword! Check out the screenshot below:

Don’t let the big companies fool you, Virt-back is free, opensource, and public domain.