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 / 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
#
@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 / 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 / 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]
/docs
/target
/lib
/classes
/checkouts
pom.xml
*.jar
*.class
.lein-deps-sum
.lein-failures
@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))
@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!
; Depends on [com.notnoop.apns/apns "0.1.6"].
(:import ('com.notnoop.apns APNS))
(defn send-push-notification [device-token message]
(let [service (.build (.withSandboxDestination
(.withCert (APNS/newService) "resources/apns-dev-cert.p12" "password")))
payload (.build (.alertBody (APNS/newPayload) message))]
(.push service device-token payload)))
(defn model-from-sequence
"Returns a transition matrix of 'depth' from 'sequence'"
[depth sequence]
(loop [accum {} chunks (partition (inc depth) 1 (seq sequence))]
(if (seq? chunks)
(let [chunk (first chunks)
prefix (drop-last chunk)
suffix (last chunk)]
(recur (assoc accum prefix (conj (get accum prefix []) suffix)) (next chunks)))
accum)))
@johnptoohey
johnptoohey / starred items.md
Created September 24, 2016 14:46 — forked from otw1248/starred items.md
star,good,recommendations

Internet Scale Services Checklist: A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."
System Design Cheatsheet :Picking the right architecture = Picking the right battles + Managing trade-offs