This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
defaults write com.apple.dashboard mcx-disabled -boolean YES | |
killall Dock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
connect() { | |
ssh proxyserver -fN | |
} | |
disconnect() { | |
kill -n 9 $(pgrep -f "ssh proxyserver -fN") 2>/dev/null | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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([]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
int n, k; | |
n = 12345; | |
while (n >= 1) { | |
k = n%10; | |
printf("%d\n", k); | |
n /= 10; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[q for q in[range(90)[x:x+4]for x in range(90-4)]if sum(q)==90].pop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( [ -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" | |
) |