Skip to content

Instantly share code, notes, and snippets.

View owainlewis's full-sized avatar

Owain Lewis owainlewis

View GitHub Profile
@owainlewis
owainlewis / Postgresql Quick Guide
Created January 12, 2012 19:09
Postgresql Cheat Sheet
Postgresql Cheat Sheet
===============================
start: psql -U username databasename
quit: \q
list all: \d
list tables: \dt
list all databases: \l
@owainlewis
owainlewis / _analytics.haml
Created March 9, 2012 20:06
Google Analytics HAML
:javascript
var _gaq = _gaq || [];
_gaq.push(['_setAccount', YOUR_CODE']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
@owainlewis
owainlewis / protocols.clj
Created March 9, 2012 23:07
Clojure IO Protocols
(defprotocol IO
"A protocol for reading and writing"
(read-file [this])
(write-file [this]))
(extend-protocol IO
String
(read-file [file]
(with-open [rdr (clojure.java.io/reader file)]
(reduce conj [] (line-seq rdr))))
@owainlewis
owainlewis / gist:2152665
Created March 21, 2012 20:38
ClojureScript Setup OSX

Install ClojureScript

git clone git://github.com/clojure/clojurescript.git
cd clojurescript
./script/bootstrap

In ClojureScript dir

export CLOJURESCRIPT_HOME=$HOME/

export PATH=$PATH:$CLOJURESCRIPT_HOME/bin:$CLOJURESCRIPT_HOME/script

@owainlewis
owainlewis / core.clj
Created April 4, 2012 19:58
Clj-webdriver test
(ns selenium-test.core
(:use midje.sweet)
(:use [clj-webdriver.taxi]))
(set-driver! {:browser :firefox})
(to "http://www.boxuk.com/")
(facts "About the homepage"
(visible? "#content") => true)
@owainlewis
owainlewis / sieve.py
Created April 4, 2012 21:49
Sieve of Erastothenes
from math import sqrt
# Sieve of Erastothenes
def sieve(n):
candidates = list(range(n))
# We only need to check up to the square root of n
upto = int(sqrt(n)) + 1
@owainlewis
owainlewis / problem07.clj
Created April 5, 2012 12:41
Fast prime sort algorithm
(ns euler.problem7
(:use [euler.core]))
;; The algorithm for this is
;; - Start at the first 1000 primes
;; - If there are not enough primes then try again at 2000 etc
(defn get-nth-prime [n, max]
"Returns the nth prime"
(let [primes (sieve max)]
@owainlewis
owainlewis / gist:2361826
Created April 11, 2012 19:43
Cassandra CLI

Cassandra CLI

Startup

  1. bin/cassandra -f
  2. bin/cassandra-cli
@owainlewis
owainlewis / query.rb
Created April 26, 2012 17:52
Ruby HTTP DSL
# A Micro DSL for NET/HTTP
require 'net/http'
require 'net/https'
require "uri"
# Base class for making HTTP connections
module Query
@owainlewis
owainlewis / chunks.rb
Created April 28, 2012 23:35
Grouping sequence by n in Ruby
def group_sequence_by n, sequence
Array.new.tap do |result|
sequence.each_slice(n) { |item| result << item }
end
end