Skip to content

Instantly share code, notes, and snippets.

@mariofusco
mariofusco / MnemonicsCoder.scala
Created June 12, 2011 16:23
Encodes a number in one (or more) list of words corresponding to its phone mnemonic code
class MnemonicsCoder(words: List[String]) {
private val mnemonics = Map('2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ")
/** Invert the mnemonics map to give a map from chars 'A' ... 'Z' to '2' ... '9' */
private val charCode: Map[Char, Char] =
for ((digit, str) <- mnemonics; letter <- str) yield (letter -> digit)
/** Maps a word to the digit string it can represent */
@hmarr
hmarr / gist:1013596
Created June 8, 2011 01:22
post{,de}activate scripts for virtualenvwrapper
#!/bin/zsh
# Global virtualenvwrapper postactivate, lives in $WORKON_HOME/postactivate
# Remove virtual env from start of PS1 as it's in RPROMPT instead
PS1="$_OLD_VIRTUAL_PS1"
PROJECT_DIR="$HOME/projects/$(basename $VIRTUAL_ENV)"
if [ -d $PROJECT_DIR ]; then
# If we aren't already within the project dir, cd into it
@axiomsofchoice
axiomsofchoice / hello.c
Created June 5, 2011 01:48
Simple hello world C prog for testing emscripten's handling of stdio.h
#include <stdio.h>
int main(int argc, char **argv) {
FILE *fp;
char mc ;
fp = fopen(argv[1],"r") ;
printf("Reading contents of file\n");
while((mc = (char) fgetc (fp)) != EOF) {
@axiomsofchoice
axiomsofchoice / irc_clients.sparql
Created June 4, 2011 22:31
Query DBpedia for GPL licensed IRC clients
## An attempt to query the data here: http://en.wikipedia.org/wiki/Comparison_of_Internet_Relay_Chat_clients
## via http://dbpedia.org/spraql to determine which IRC clients for Windows are GPL licensed
prefix dbo: <http://dbpedia.org/ontology/>
prefix dbpprop: <http://dbpedia.org/property/>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix yago: <http://dbpedia.org/class/yago/>
select distinct ?client ?label ?license ?os
@axiomsofchoice
axiomsofchoice / prime_birthday.php
Created May 30, 2011 20:47
Prime Birthday Computation Script
<html>
<body>
<form action="prime_birthday.php" method="post">
Day: <input type="text" name="day" />
Month: <input type="text" name="mon" />
Year: <input type="text" name="year" />
<input type="submit" />
</form>
@axiomsofchoice
axiomsofchoice / sparcurl.sh
Created May 17, 2011 12:27
Using curl to query SPARQL endpoints
curl -H "Accept: application/sparql-results+xml" "http://localhost:8000/sparql/" --data-urlencode "query=SELECT ?s ?p ?o { ?s ?p ?o . }"
@shellac
shellac / dbpedia-load
Created April 18, 2011 15:42
Loading some of dbpedia locally
$ curl -O http://openjena.org/repo-dev/com/hp/hpl/jena/tdb/0.8.10-SNAPSHOT/tdb-0.8.10-20110325.114138-12.zip
...
$ unzip tdb-0.8.10-20110325.114138-12.zip
...
$ export TDBROOT=TDB-0.8.10-SNAPSHOT
$ PATH=$TDBROOT/bin:$PATH
$ curl -O http://downloads.dbpedia.org/3.6/en/external_links_en.nt.bz2
$ curl -O http://downloads.dbpedia.org/3.6/en/article_categories_en.nt.bz2
$ curl -O http://downloads.dbpedia.org/3.6/en/homepages_en.nt.bz2
$ bzcat *.bz2 | tdbloader2 --loc DBpedia /dev/stdin
@axiomsofchoice
axiomsofchoice / binarysearch.py
Created April 18, 2011 15:29
An attempt at Jon Bently's binary search algorithm challenge from his book "Programming Pearls"
"""
An implementation of binary search, based on the challanges in the following blog posts:
http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html
http://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/
http://www.solipsys.co.uk/new/BinarySearchReconsidered.html?tw
This was not my first attempt however, there was a broken version (of course)
that I wrote prior to running it for the first time. Sadly I didn't take a
snapshot before I fixed it but the bug was fairly major; although I'd worked
@axiomsofchoice
axiomsofchoice / seq.hs
Created March 22, 2011 23:38
A brute-force attempt to test a few examples for the "sequence" puzzle
let primes = [2,3,5,7] in let mult (x,y) = x*y in let {f 0 ls = ls ; fn ls = map mult (zip primes (f (n-1) ls)) } in f 3 primes
@axiomsofchoice
axiomsofchoice / moire-ball.svg
Created March 19, 2011 00:22
Using a mask and animation to demonstrate Moire patterns
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.