DMesg with human readable timestamps (BASH)

By default, dmesg uses seconds of uptime for it's timestamps, which in less than useful if you're trying to quickly check the time an entry was logged at. Where available /var/log/kern.log can be used to get timestamped entries, but where not available the function below gives a dmesg analog with human readable timestamps

Read more…

Disabling Wifi Power Save (Misc)

My Android phone regularly disconnects and (immediately) reconnects to wifi. That's not a huge issue for buffered video streaming, but is an issue for VOIP, SSH connections etc. Plus I use Tasker to trigger actions when disconnected from a specific SSID, so it means the screen changes whilst those actions trigger.

Android's "smart network switch" was already turned off for causing similar issues, and the fix in my case seems to have been to disable Power-save for Wireless connections

Read more…

Querystring parsing (Javascript)

A pair of utility functions to handle parsing of querystring like strings in javascript

This may simply be a string rather than the querystring itself, so handles any string where key value pairs are ampersand (&) delimited

The encoder accepts an object, and will generate an & delimited string

Read more…

Place AJAX GET request and trigger callback function with result (Javascript)

Simple Javascript function to place a xmlhttp request (supporting a range of browsers) and trigger a callback function once the request has been satisfied

This is one of the functions I often find myself looking at older projects to find rather than re-writing it. Yes you can do the same with jQuery, but that's only really a valid route if you're already loading jQuery. Otherwise you're loading an entire framework for no real benefit

Read more…

Calculate Edit Distance between two strings (Python)

Short snippet to calculate the edit distance (or Hamming Distance) between two strings in Python

The Hamming distance is just the number of differing bits within the string, so given two single char strings:

  • a: 01100001
  • b: 01100010

The Hamming distance would be 2 as the penultimate and last bit differ.

The edit distance is useful in basic cryptanalysis as for some cipher types (basically mechanisms where the key is repeated, i.e. ECB) it can help you discern the length of the key used - out of multiple tries at the keysize, the smallest (normalised) edit distance probably best indicates the key used.

Read more…