Skip to content

Instantly share code, notes, and snippets.

@stesh
stesh / gist:8698674
Created January 29, 2014 22:37
youtube2mp3
#!/bin/bash
[ -z "$1" -o -z "$2" ] && (
cat <<EOF >&2
Usage: $0 <YouTube URL> <filename>
EOF
exit 1
)
URL="$1"
@stesh
stesh / gist:8796219
Created February 4, 2014 02:02
Overcoming library path silliness in SWI Prolog on OS X
#!/bin/sh
app="/Applications/SWI-Prolog.app"
export SWI_HOME_DIR="$app/Contents/swipl"
exec "$app/Contents/MacOS/$(basename $0)" $@
>>> from Queue import PriorityQueue
>>> l = [PriorityQueue()] * 10
>>> [hash(x) for x in l]
[-9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054, -9223372036579180054]
>>> l = [PriorityQueue() for _ in range(10)]
>>> [hash(x) for x in l]
[275597326, 275597335, 275597371, -9223372036579178388, 275597470, -9223372036579178289, 275597829, -9223372036579177930, 275597928, -9223372036579177831]
#!/usr/bin/env ruby
puts ARGV.map {|x| x += '@tcd.ie'}.join(', ')
bool has_left_recursion(Grammar g) {
for (vector<Rule>::iterator i = g.rules.begin(); i != g.rules.end(); ++i) {
if (i->mother == i->dtrs.front()) return true;
}
return false;
}
public static int[] countLetters(String input) {
int[] results = new int[26];
for (int i = 0; i < input.length(); i++) {
int cur = input.toLowerCase().charAt(i);
if (cur >= 'a' && cur <= 'z') {results[cur - 'a']++;}
}
return results;
}
#!/usr/bin/env ruby
def y(n)
case n
when 0 then 1
when 1 then 0
when 2 then -4
when 3 then 0
else y(n - 4)
end
array2string(a : ARRAY[G]) : STRING is
local
k : INTEGER
do
Result := "<< "
from
k := a.lower
until
k = a.upper
loop
/**
* As described in 'updates' in the nodes
*/
void CHART::do_cell(int i, int k) {
Rule r;
Category A, B, C;
int A_included, B_included;
ón __todhchaí__ impórtaigh roinnt