Skip to content

Instantly share code, notes, and snippets.

View tantalor's full-sized avatar

John Tantalo tantalor

View GitHub Profile
@tantalor
tantalor / merge.py
Created May 5, 2014 17:51
Merge Algorithm
def merge(streams):
# Keep track of the least value in each stream.
head = [stream.next() for stream in streams]
while len(head):
# Yield the least value of all streams.
next = min(head)
yield next
index = head.index(next)
try:
# Get next value from that stream.
def bin(x, k=0):
d = {0:'000', 1:'001', 2:'010', 3:'011', 4:'100', 5:'101', 6:'110', 7:'111'}
return ''.join([d[int(dig)] for dig in oct(x)]).lstrip('0').zfill(k)
javascript:(function%20()%20{var%20selection%20=%20window.getSelection%20?%20window.getSelection()%20:document.getSelection%20?%20document.getSelection()%20:document.selection%20?%20document.selection.createRange().text%20:%20%27%27;if%20(selection)%20{selection%20=%20String(selection);}if%20(selection)%20{var%20match%20=%20selection.match(%27\/(.*)\/%27);var%20ipa;if%20(match%20&&%20match[1])%20{ipa%20=%20match[1];}if%20(!ipa)%20{ipa%20=%20prompt(%22Couldn%27t%20find%20any%20IPA.%20Type%20it%20in%20instead?%22);}if%20(ipa)%20{ipa%20=%20ipa.replace(/./g,%20function%20(c)%20{if%20(/%u0(...)/.test(escape(c)))%20{return%20escape(c).replace(/%u0(...)/g,%20%27&#x$1;%27);}%20else%20{return%20c;}});var%20request%20=%20{txt:%20%27<phoneme%20alphabet=%22ipa%22%20ph=%22%27+ipa+%27%22>%20</phoneme>%27,voice:%20%27crystal%27};var%20iframe%20=%20document.createElement(%27iframe%27);iframe.name%20=%20iframe.id%20=%20%22iframe%22+new%20Date().getTime();document.body.appendChild(iframe);var%20form%20=%20document.createElemen
// John Tantalo
jQuery.fn.chain = function (fn)
{
var self = this;
return function ()
{
if (!self.size()) return;
fn(self.eq(0), self.slice(1).chain(fn));
}
alias svnclean="for i in \$(svn st | grep \? | cut -c 9-); do echo \$i && rm \$i; done"
escape ``
screen -t "host 1" ssh host1
screen -t "host 1" ssh host1
screen -t "host 2" ssh host2
screen -t "host 2" ssh host2
screen -t "host 3" ssh host3
screen -t "host 3" ssh host3
<div id="slideshow">
<img src="http://farm6.static.flickr.com/5243/5373962623_0e23ed169b_t.jpg">
<img src="http://farm6.static.flickr.com/5007/5374562138_30e01a767f_t.jpg" style="display:none">
<img src="http://farm6.static.flickr.com/5288/5374562162_d48ca16567_t.jpg" style="display:none">
<img src="http://farm6.static.flickr.com/5084/5374562208_3e1bbe58cc_t.jpg" style="display:none">
<img src="http://farm6.static.flickr.com/5086/5374562182_5ec5c14403_t.jpg" style="display:none">
</div>
<script type="text/javascript">
var ims = document.getElementById('slideshow').children;
@tantalor
tantalor / bliff.pl
Created March 12, 2011 03:07
Combines svn blame and diff.
#!/usr/bin/perl
use strict;
use List::Util 'max';
my ($from, $to) = @ARGV
or die "usage: $0 OLD-URL[\@OLDREV] NEW-URL[\@NEWREV]\n";
my @diff = `svn diff $from $to` or die;
my @blame = map {/^\s*(\d+)/} `svn blame $to` or die;
{"html": "line<br>break"}
@tantalor
tantalor / generator.js
Created April 20, 2011 23:43
buffering asynchronous iterator pattern
// produce: accepts a cb which is called with an array of items
// initial: initial array of results to return
// returns a function which accepts a cb which is called with one item
// each time it is called
function generator(produce, initial) {
var items;
var waiting = [];
var next = function (cb) {
if (items && items.length) {