Skip to content

Instantly share code, notes, and snippets.

if ( window.addEventListener ) {
var pressed_keys = [];
var cheat = "38,38,40,40,37,39,37,39,66,65";
window.addEventListener("keydown", function(e){
pressed_keys.push( e.keyCode );
if ( pressed_keys.toString().indexOf( cheat ) >= 0 ) {
// User entered the cheat - do something HILARIOUS
pressed_keys = []; // wipe the keys
}
}, true);
ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]'
sudo kill -HUP `ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}'`
[ec2-user@hop ~]$ curl --head http://people.com.cn/
HTTP/1.0 200 OK
Server: nginx
Date: Mon, 14 Feb 2011 16:22:31 GMT
Content-Type: text/html
Content-Length: 152319
Last-Modified: Mon, 14 Feb 2011 16:18:17 GMT
Vary: Accept-Encoding
Accept-Ranges: bytes
X-Cache: MISS from www21.people.com.cn
@hjst
hjst / gist:836964
Created February 21, 2011 11:52
Examples of Youtube API searches for videos by user AND tag
HTTP GET URIs in the form of:
http://gdata.youtube.com/feeds/api/videos/-/{http://gdata.youtube.com/schemas/2007/keywords.cat}tag?author=username
Examples:
Videos uploaded by user BBCWorldwide with tag "wildlife":
http://gdata.youtube.com/feeds/api/videos/-/{http://gdata.youtube.com/schemas/2007/keywords.cat}wildlife?author=BBCWorldwide
@hjst
hjst / csv_gen.py
Created March 2, 2011 01:49
dirty csv test data gen
#! /usr/bin/env python
from optparse import OptionParser
import sys, csv, os.path, random
def main():
usage = "usage: %prog [options] arg"
parser = OptionParser(usage)
parser.add_option("-t", "--template", dest="filename",
help="use FILENAME as CSV template")
#! /usr/bin/env perl
sub toss( $ ); # prints coin toss results for $ coins
if( !defined($ARGV[0]) )
{
# If there was no command line argument
print "Number of coins not specified - using default number: 3\n\n";
toss( 3 );
}
@hjst
hjst / sleepsort.sh
Created September 28, 2011 04:15
./sleepsort.sh 4 6 3 2 5 9 1
#!/bin/bash
function sleepsort() {
sleep "$1"
echo "$1"
}
while [ -n "$1" ]; do
sleepsort "$1" & shift
done
wait
@hjst
hjst / gist:1326755
Last active November 21, 2018 05:22
Format a javascript Date object as a 12h am/pm time string.
function format_time(date_obj) {
// formats a javascript Date object into a 12h AM/PM time string
var hour = date_obj.getHours();
var minute = date_obj.getMinutes();
var amPM = (hour > 11) ? "pm" : "am";
if(hour > 12) {
hour -= 12;
} else if(hour == 0) {
hour = "12";
}
@hjst
hjst / gist:1326758
Created October 31, 2011 02:12
Use jQuery to get a Pinboard tag for a given user.Pinboard uses the 'cb' callback method name in it's JSON.
function GetPinboardTag(user, tag, count, handler) {
$.ajax({
url:'http://feeds.pinboard.in/json/v1/u:'+user+'/t:'+tag+'?count='+count,
jsonp:"cb",
dataType:'jsonp',
success: handler
});
}
@hjst
hjst / article_template.tex
Created February 3, 2012 06:39
LaTeX article class template
% See http://code.google.com/p/latex-makefile/ for a useful Makefile
% --- BEGIN HEADER
\documentclass[11pt]{article}
\usepackage{graphicx}
\topmargin -1.5cm % read Lamport p.163
\oddsidemargin -0.04cm % read Lamport p.163
\evensidemargin -0.04cm % same as oddsidemargin but for left-hand pages
\textwidth 16.59cm
\textheight 21.94cm