Skip to content

Instantly share code, notes, and snippets.

View johnptoohey's full-sized avatar
🎯
Focusing

John Toohey johnptoohey

🎯
Focusing
View GitHub Profile
@johnptoohey
johnptoohey / Queues.clj
Last active December 15, 2015 09:19 — forked from gorsuch/gist:4617330
Taken from [here](http://blog.marrowboy.co.uk/2011/10/21/worker-queues-in-clojure/), recording so I don't lose it:
```clj
(defn new-q [] (java.util.concurrent.LinkedBlockingDeque.))
(defn offer!
"adds x to the back of queue q"
[q x] (.offer q x) q)
(defn take!
@johnptoohey
johnptoohey / gist:4496886
Last active December 10, 2015 21:39
Luhn check for creditcard numbers
(defn- digits [n]
(map #(Character/digit % 10) (str n)))
(defn luhn? [n]
(let [sum (reduce + (map
(fn [d idx]
(if (even? idx)
(reduce + (digits (* d 2)))
d))
(reverse (digits n))
/docs
/target
/lib
/classes
/checkouts
pom.xml
*.jar
*.class
.lein-deps-sum
.lein-failures
@johnptoohey
johnptoohey / gist:4360192
Last active December 10, 2015 01:38 — forked from stonegao/gist:1228539
Clojure: Storm Example
(use 'backtype.storm.clojure)
(use 'backtype.storm.config)
(require '[backtype.storm [thrift :as thrift]])
(import 'storm.starter.spout.RandomSentenceSpout)
(import 'backtype.storm.LocalCluster)
(defboltfull suffix-bolt ["word"]
:params [suffix]
:let [conf-state (atom nil)]
:prepare ([conf context collector]
@johnptoohey
johnptoohey / gist:4360179
Last active June 29, 2016 10:14 — forked from yulrizka/gist:4251956
Storm: Nimbus startup script
#!/bin/bash
#
# /etc/init.d/storm-nimbus
#
# Startup script for storm-nimbus
#
# chkconfig: 2345 20 80
# description: Starts and stops storm-nimbus
#. /etc/init.d/functions
stormBin=/home/user/storm/storm-0.8.1/bin/storm
@johnptoohey
johnptoohey / SimpleMarkovChain.clj
Created December 22, 2012 17:37 — forked from jackrusher/SimpleMarkovChain.clj
Clojure: SimpleMarkovChain
(defn analyse
"Returns a transition matrix of 'depth' from 'sequences'"
[depth sequences]
(apply merge-with concat
(flatten
(map #(map (fn [k v] (hash-map k v))
(partition depth 1 %)
(map (fn [x] (list x)) (nthrest % depth)))
sequences))))
@johnptoohey
johnptoohey / hack.sh
Created April 1, 2012 15:41 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#