Skip to content

Instantly share code, notes, and snippets.

View owainlewis's full-sized avatar

Owain Lewis owainlewis

View GitHub Profile
@owainlewis
owainlewis / partial.clj
Created July 19, 2012 08:16
Partial Function Application
(defn add [a b] (+ a b))
(def addTwo (partial add 2))
(addTwo 5)
(map addTwo [1 2 3])
@owainlewis
owainlewis / pattern.rb
Created July 26, 2012 12:23
Pattern Matching DSL
# Pattern matching DSL ideas
class Object
def method_missing method_name, *args, &block
if method_name.to_s == "_"
:default
else
super
end
end
@owainlewis
owainlewis / .travis.yml
Created July 26, 2012 21:19
Travis for Rails 3
language: ruby
rvm:
- 1.9.3
env:
- DB=sqlite
- DB=mysql
- DB=postgresql
script:
- RAILS_ENV=test bundle exec rake --trace db:migrate test
before_script:
@owainlewis
owainlewis / socket_chat.py
Created July 31, 2012 15:15
Python socket based chat server
#!/usr/bin/python3
import socket, sys, threading
# Simple chat client that allows multiple connections via threads
PORT = 9876 # the port number to run our server on
__version__ = "0.0.1"
class ChatServer(threading.Thread):
import urllib2, urlparse
# Check a text file of urls to make sure they return a status 200
class StatusChecker(object):
""" Check the status codes of multiple URLS """
def __init__(self, url_file="urls.txt"):
self.url_file = url_file
@owainlewis
owainlewis / test.watchr.rb
Created August 2, 2012 15:52
watchr for test unit
#!/usr/bin/env ruby
def method_missing(meth, *args, &block)
if meth.to_s =~ /^run_(.+)$/
system 'clear'
system "rake test:#{$1}"
else
super
end
end
@owainlewis
owainlewis / import.py
Created August 7, 2012 11:29
Boxuk database backup utility
#!/usr/bin/python3
from urllib.request import *
import re
import shutil
import os
# Will look through all available databases and list them
# Can also pull down the database into your current directory if required
@owainlewis
owainlewis / zipper.py
Created August 8, 2012 19:36
File zipper
import shutil
import os
import sys
# Simple file zipper for concatenation of various files
class Zipper:
def __init__(self, path, *args, **kwargs):
@owainlewis
owainlewis / multimethod.rb
Created August 11, 2012 18:32 — forked from alandipert/multimethod.rb
Multimethods in Ruby
class Multimethod
attr_accessor :dispatch, :methods, :heirarchy, :default_method
class NoMatchingMethodError < StandardError
end
def initialize(&dispatch)
@dispatch = dispatch
@methods = []
@heirarchy = {}
end
@owainlewis
owainlewis / functors.ml
Created August 12, 2012 19:39
OCaml Functors
type comparison = Less | Equal | Greater
module type ORDERED_TYPE =
sig
type t
val compare: t -> t -> comparison
end;;
module type ORDERED_TYPE = sig type t val compare : t -> t -> comparison end