Skip to content

Instantly share code, notes, and snippets.

contains(X, [X | _]).
contains(X, [_ | T]) :- contains(X, T).
equals([], []).
equals([_|T1], [_|T2]) :- equals(T1, T2).
len([], 0).
len([_|T], L) :- len(T, L1), succ(L1, L).
empty([]).
@stesh
stesh / gist:1230746
Created September 20, 2011 23:41
Keep a tunnel to a proxy server open on a dodgy shared Internet connection
#!/bin/bash
connect() {
ssh proxyserver -fN
}
disconnect() {
kill -n 9 $(pgrep -f "ssh proxyserver -fN") 2>/dev/null
}
@stesh
stesh / gist:1130900
Created August 7, 2011 22:59
Cobbled-together backup routine. (Don't use this without modification)
#!/usr/bin/perl
use strict;
use warnings;
$< and die "This won't work unless run by root";
my @errors;
sub log_error {
push(@errors, pop);
@stesh
stesh / gist:1130885
Created August 7, 2011 22:37
Disable Dashboard on OS X
#!/bin/sh
defaults write com.apple.dashboard mcx-disabled -boolean YES
killall Dock
int Dict::update(string s) {
if (accept(s)) return;
int index = 0;
NodePtr n1, n2;
for (index = 0; index <= s.size(); index++) {
if ((index->match(s[index])) == NULL) n2 = n1->update(s[index]);
n1 = n2;
bst2array(tree : BST[G]; a : ARRAY[G]) is
require
tree /= Void
do
-- Traverse the tree in-order
if tree.left /= Void then
-- Recursively add all the elements of the left subtree
bst2array(tree.left, a)
end
add_node(item : G; root : BIN_NODE[G]) is
local
previous_node, current_node, new_node : BIN_NODE[G]
do
if root = Void then
-- The trivial case, creating the root of the tree
-- with no subtrees
create root
root.build(item, Void, Void)
count := 1
q = lambda l : l if len(l) <= 1 else (q([x for x in l[1:] if x < l[0]]) + [l[0]] + q([x for x in l[1:] if x >= l[0]]))
digraph CYK_parse {
rankdir=LR;
node [shape = point,height=0.3]; 0,1,2,3,4,5,6;
// k = 1
// --------------------
0 -> 1 [label = "DET",color=black];
0 -> 1 [label = "the",color=red];
#!/usr/bin/env ruby
def mel(f)
include Math
(1000.quo(Math.log(2))) * Math.log(1 + (f.quo(1000)))
end
1.upto(1000) do |f|
puts "#{f} Hz --> #{mel(f).round(1)} mel"
end