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:

April 23, 2015

How to Implement One-Time Passwords Serverside

Kindly avail yourself of the following python code, which comprises the backend of a simple, one-time password system:
You'll need to install and requests to use it.

April 17, 2015

How to get Out of a Recession

Those who know me know me to be a rather big supporter of the left-wing British MP George Galloway, because of his foreign policy work in the Middle East. This is a personal bias I have.

My economic views, however, are less personal and more scientifically justified. When any economic downturn hits, there are those in governments that say we need to collectively tighten our belts till we grow again and because we the people are the government, the government is included in this list This is what I would term the austerity lot. There are others, however, who feel that government must be the spender of last resort, thus expanding and making up for the slack in the rest of the economy -- the Keynesians. Which strategy does better?

To get an answer, we must define the terms -- what does better mean? Better in the sense of a shallower dip in aggregate economic growth as measured by GDP. Our three candidate countries -- posterboys for austerity, Germany, posterboys for ramping up government spending, China, and a third country that did something in between, the United States. The results are below, followed by the code used to generate the plot:

April 1, 2015

How to see my Shared Links

So, earlier this morning, I rewrote the links list. Future directions include using the document titles instead of the URLs and making the page prettier. The source code for the web application is below:

How to tell When the Next Caltrain is Leaving

Until I decide otherwise, I'm in south bay and am without a car. So, I'm reliant on Caltrain, whose website leaves much to be desired in the area of easy to access information. How do I know this? Well, if I get annoyed with the user experience, then you can be sure a majority of users are frustrated. However, the good people at caltrans do provide GTFS-compliant feeds, which are trivial to parse. Without further ado:

And a run of it:

March 30, 2015

What is a Splay Tree's Worst Case Performance

A Splay tree is seemingly, a combination of a binary tree and a linked list, with performance characteristics of the former at average case and the latter at worst case. But, a big O reference page suggests that the average and worst cases are the same. What gives?

March 23, 2015

How to Calculate Readability of Text

Readability is defined as the ease with which a written text can be understood by a reader. There are a bunch of metrics for calculating the readability of a piece, many of which are incorporated into koRpus. To use this, read in a text file from your local drive in the following manner: R will then spit out something looking like this:

March 21, 2015

How to Run Sirc on FreeBSD

I'm a big fan of small. My preferred IRC client is only 59k for instance (that's right kilobytes, not megabytes or gigabytes). I know most of the known world doesn't value minimalism, but I fixed the port on FreeBSD and have submitted a patch to fix it.

How to make Java Less Chatty

When I program, I like to have the logging up to the max. Others don't. The shell pipe below filters the logging messages out, leaving only the run output, output first:

% java -jar foo.jar

  .   ____          _            __ _ _g,
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 :: Spring Boot ::        (v1.2.1.RELEASE)

Sending a new message.
Received  success!
And the magic incantation to remove all the extraneous messages is: mvn spring-boot:run | grep -v "`date +'%Y-%m-%d %H:%M'`" | grep -v '^\['; I do hope that makes your getting on with peers a lot easier.