Skip to content

Instantly share code, notes, and snippets.

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
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
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;
@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
@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: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
}
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([]).
#include <stdio.h>
int main() {
int n, k;
n = 12345;
while (n >= 1) {
k = n%10;
printf("%d\n", k);
n /= 10;
}
[q for q in[range(90)[x:x+4]for x in range(90-4)]if sum(q)==90].pop()
( [ -f /var/run/lighttpd.pid ] && [ $(pgrep lighttpd | head -n 1) = $(head -n 1 /var/run/lighttpd.pid) ] ) || (
/etc/init.d/lighttpd restart
echo \
"To: webmaster@netsoc.tcd.ie
From: root@cubewww.netsoc.tcd.ie
Subject: Automated restart of lighttpd
Attempted automated restart of lighttpd on $(date)
" | sendmail "webmaster@netsoc.tcd.ie"
)