Skip to content

Instantly share code, notes, and snippets.

View seadowg's full-sized avatar

Callum Stott seadowg

View GitHub Profile
@seadowg
seadowg / tumble.html
Created February 28, 2011 00:05
Twitter/Flickr links in a list. Will style correctly in Tumblr Cargo theme. Quick paste for a mate.
<ul class="faint" id="links">
<li><a href="http://www.twitter.com" class="rounded">Twitter</a></li>
<li><a href="http://www.flickr.com"class="rounded">Flickr</a></li>
</ul>
@seadowg
seadowg / grav.py
Created March 3, 2011 21:33
Python script for setting your Ubuntu user pic as your Gravatar (command: 'python grav.py email@example.com')
import hashlib, urllib2, sys, os
class Gravatar:
def __init__(self, email):
self.email = email
self.hash = hashlib.md5(self.email.lower()).hexdigest()
def get(self):
try:
@seadowg
seadowg / poweroftwo.py
Created April 7, 2011 20:50
I once asked the fastest to calculate if a number was a power of two or not and I choked. Here is a nifty little way to do it.
import sys
def isapoweroftwo(n):
if n == 0:
return False
if n & (n - 1) == 0:
return True
@seadowg
seadowg / gensem.py
Created April 27, 2011 13:14
A general semaphore implementation
class Semaphore:
def init(self, n):
self.lock = BinSemaphore(1)
self.delay = BinSemaphore(0)
self.var = n
def wait(self):
self.lock.wait()
self.var = self.var - 1
if self.var < 0:
@seadowg
seadowg / build.xml
Created May 30, 2011 21:49
Scala ant build script (OS X with brew install of scala)
<project name="scalaIsAwesome" basedir="." default="build">
<property name="scala-compiler.jar"
value="/usr/local/Cellar/scala/2.8.1/libexec/lib/scala-compiler.jar"/>
<property name="scala-library.jar"
value="/usr/local/Cellar/scala/2.8.1/libexec/lib/scala-library.jar"/>
<path id="scala.classpath">
<pathelement location="${scala-compiler.jar}"/>
<pathelement location="${scala-library.jar}"/>
</path>
<taskdef resource="scala/tools/ant/antlib.xml">
@seadowg
seadowg / install_buildr.sh
Created August 18, 2011 15:13
Install Buildr on OSX
gem install rjb -v 1.3.3 --platform ruby
gem install buildr
@seadowg
seadowg / rempdf
Created November 20, 2011 02:17
Delete pdfs from downloads folder on OSX
#!/bin/bash
rm /Users/$USER/Downloads/*.pdf
@seadowg
seadowg / Class.scala
Created November 26, 2011 21:53
`.class` in Scala
// I always run into massive problems when trying to write Scala that uses Java libraries. Recently
// one thing that threw me off was trying to do the following:
val class = MyAwesomeType.class
// This is often used in Java to get the 'Class' class for a class (yeah, I know). But how do we do
// this in Scala?
val class = MyAwesomeType.class // No. This reports that there is no 'class' member for the type
@seadowg
seadowg / map.java
Created December 5, 2011 00:05
HashMap built naively with TDD (and Tests)
// The following code is a series of test that were written in the order you'll read them. After
// each test was written it was run against the HashMap and the implementation was updated if it
// failed. The HashMap code is the final implementation that was built naively to pass each test.
// The Tests:
public class HashMapTest {
private HashMap map;
// Set up an empty map before each test
@seadowg
seadowg / echo.rb
Created February 12, 2012 16:18
Using echo in JRuby
include Java
require '$SCALA_HOME/scala-library.jar'
require 'lib/echo.jar'
include_class Java::com.github.oetzi.echo.core.Behaviour
include_class Java::com.github.oetzi.echo.core.Event
beh = Behaviour.new { | time | 5 }
event = Event.new
beh.at(1)