Skip to content

Instantly share code, notes, and snippets.

@hjst
hjst / ticker.pl
Last active August 29, 2015 14:03
Time ticker with variable line length for easy visual recognition of ssh session freezes
#!/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 April 18, 2015 06:19
This adds bash-history-esque !! and !$ bindings to fish shell (and the substitution is immediate, which is neat)
# 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 June 23, 2015 04:35
Makes reading stardict dictionary searches in a terminal more bearable.
#!/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() {
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