Skip to content

Instantly share code, notes, and snippets.

Owain Lewis owainlewis

Block or report user

Report or block owainlewis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Postgresql Quick Guide
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 Mar 9, 2012
Google Analytics HAML
View _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 Mar 9, 2012
Clojure IO Protocols
View protocols.clj
(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 Mar 21, 2012
ClojureScript Setup OSX
View gist:2152665

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 Apr 4, 2012
Clj-webdriver test
View core.clj
(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 Apr 4, 2012
Sieve of Erastothenes
View sieve.py
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 Apr 5, 2012
Fast prime sort algorithm
View problem07.clj
(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)]
View gist:2361826

Cassandra CLI

Startup

  1. bin/cassandra -f
  2. bin/cassandra-cli
View query.rb
# 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 Apr 28, 2012
Grouping sequence by n in Ruby
View chunks.rb
def group_sequence_by n, sequence
Array.new.tap do |result|
sequence.each_slice(n) { |item| result << item }
end
end
You can’t perform that action at this time.