July 26, 2015

How to Deploy a Rails Application in One Command

The second facet of Joel's software test is can you make build in one step?. The rake task below will push all changes to heroku and your secondary upstream ("origin"), run migrations on heroku, and deploy it there, Without further ado, the task is pasted below...

July 12, 2015

How to View HTML Messages in MH

Code above will let you take an nmh folder, save a message to a file, upload it to a remote server, and remove the message from the local mailbox to be viewed with a web browser. I use nmh for my work mailbox, where messages often come encrypted using PGP and therefore can't be viewed on webmail. No matter how many times I tell them, senders insist on HTML mail, so I had to get a workaround.

July 10, 2015

How to See What's in Heroku

I've been away from writing for around a week, but not from coding. I've been working on notes, an anonymous blogging site, not with python (because a prolific programmer does not live by a pirate call and a serpent alone). This site is written using ruby on rails and the admin GUI is in java, with console output, as shown above.

June 29, 2015

How to know what Endpoints any Werkzeug webapp Exposes

The code above lists your flask endpoints along with their handlers in json.

How to use heroku under NetBSD

I woke up at a loss, as the notes build was broken, I'd updated my checkouts and pushed the broken code, and the heroku toolbelt wasn't behaving. This was on all my systems, except for an old checkout I had on NetBSD. However, the heroku gem wouldn't install on it. But it was missing from jsplugin, so I added it in. And presto, it started to work!

June 14, 2015

How to Authenticate Users

The code below is a simple authentication system written in python (of course) and bottlepy. It also includes a few, simple unit-tests:

For now, it only supports one site, I'll probably add multiple site support in the near future.

May 27, 2015

How to Remix My Shared Links

I share a lot of links -- by email, I tweet their aggregate statistics, I provide them in json, RSS, and compressed csv. Tonight, I added the option of getting them as well-formed, simple xml for Ibrahim. The entire method is 15 lines and embedded below:

May 21, 2015

How to Resolve Zipcodes to Timezones

A friend emailed me in the middle of the night asking me if I knew of any simple method to resolve postal codes to timezones in the United States. Enter python and flask:

There may very well be a clever way to refactor the if statement, but this does work, so I can't be bothered.

May 17, 2015

How to Monitor Network Availability

My adventures with the Internet continue. I decided to get scientific about it though. So I've written a script (in python naturally) to log when the network is down. It does so, by invoking fping in an infinite loop and checking its return code for success, in which case the subprocess module will raise an exception. This exception is caught, the time is logged and the user needs to hit a key to continue. Eventually, I'll probably design a pretty plot, to get some insight as to when the network flakes.

May 11, 2015

How to Download and Save Flickr Images

A follow up from yesterday's post on locating the direct URL to any flickr photo. I've now added save capability to the current directory. As a final step, I think I'd like to set the desktop background to the downloaded photo automatically. That's for another day, though. With the new feature, the code is below:

How to Download Flickr Images

The code above will allow you to download images from flickr, even when the photographer has disabled the downloading of their images. Just send it the URL to the any of the image sizes as the "--url=" parameter. As usual, I'm open to suggestions regarding style and readability.

April 28, 2015

How to Track my Link Sharing

If one wants to know how many links I share in a given day, check my twitter feed around 4 in the morning GMT (that's 8pm Pacific time and noon in Hong Kong/Singapore). Source code for this lives below: