Skip to content

Instantly share code, notes, and snippets.

@hjst
hjst / ticker.pl
Last active Aug 29, 2015
Time ticker with variable line length for easy visual recognition of ssh session freezes
View ticker.pl
#!/usr/bin/env perl
use strict;
use warnings;
use Sys::Hostname;
require 'sys/ioctl.ph';
main(@ARGV);
sub main {
@hjst
hjst / fish_user_key_bindings.fish
Created Apr 18, 2015
This adds bash-history-esque !! and !$ bindings to fish shell (and the substitution is immediate, which is neat)
View fish_user_key_bindings.fish
# put these in ~/.config/fish/functions/fish_user_key_bindings.fish
function bind_bang
switch (commandline -t)
case "!"
commandline -t $history[1]
commandline -f repaint
case "*"
commandline -i !
end
@hjst
hjst / define.sh
Created Jun 23, 2015
Makes reading stardict dictionary searches in a terminal more bearable.
View define.sh
#!/bin/bash
# A wrapper script for sdcv which provides line spacing and wrapping to improve
# readability.
#
# Please note: sdcv(1) relies on dictionary files being in
# /usr/share/stardict/dic
# $(HOME)/.stardict/dic
usage() {
View cheat.js
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);
View gist:563372
ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]'
sudo kill -HUP `ps -A -ostat,ppid,pid,cmd | grep -e '^[Zz]' | awk '{print $2}'`
View gist:826101
[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 Feb 21, 2011
Examples of Youtube API searches for videos by user AND tag
View gist:836964
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 Mar 2, 2011
dirty csv test data gen
View csv_gen.py
#! /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")
View coinToss.pl
#! /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 Sep 28, 2011
./sleepsort.sh 4 6 3 2 5 9 1
View sleepsort.sh
#!/bin/bash
function sleepsort() {
sleep "$1"
echo "$1"
}
while [ -n "$1" ]; do
sleepsort "$1" & shift
done
wait