Skip to content

Instantly share code, notes, and snippets.

@pmbauer
pmbauer / euler14.clj
Created August 22, 2011 03:14
Three Clojure solutions to Euler 14
(ns euler14
(:use [clojure.repl]))
(defn max-euler14 [count-fn upper-bound]
(->> (range 1 (inc upper-bound))
(map (juxt identity count-fn))
(reduce (partial max-key second))))
; idiomatic
(defn euler14-terms [n]
@pmbauer
pmbauer / euler14.clj
Created August 22, 2011 16:52
Three Clojure solutions to Euler 14
(ns euler14
(:use [clojure.repl]))
(defn max-euler14 [count-fn upper-bound]
(->> (range 1 (inc upper-bound))
(map (juxt identity count-fn))
(reduce (partial max-key second))))
; idiomatic
(defn euler14-terms [n]
@pmbauer
pmbauer / quine_gawk.awk
Created September 10, 2011 05:23
Quine, a self-printing program
BEGIN{S="BEGIN{S=\"%s\";s=S;gsub(/\\\\/,\"\\\\\\\\\",s);gsub(/\\\"/,\"\\\\\\\"\",s);printf(S,s)}";s=S;gsub(/\\/,"\\\\",s);gsub(/\"/,"\\\"",s);printf(S,s)}
@pmbauer
pmbauer / 20p_languages_panel.txt
Created September 21, 2011 18:51
Strangeloop Programming Languages Panel
Programming Languages Panel
September 20, 2011
StrangeLoop
St. Louis, Missouri
Members:
Dean Wampler: Moderator
Rich Hickey: Clojure
Jeremy Ashkenas: CoffeeScript, NY Times
Dr. Gerald Sussman: MIT Prof, SICP
@pmbauer
pmbauer / mahout.clj
Created December 22, 2011 06:42
Mahout playground buffer
;; :dependencies [[org.apache.mahout/mahout-core "0.5"]]
;; :dev-dependencies [[slamhound "1.2.0"]]
(ns mia.mahout
(:import
(java.io File)
(org.apache.mahout.cf.taste.eval RecommenderBuilder)
(org.apache.mahout.cf.taste.impl.eval
AverageAbsoluteDifferenceRecommenderEvaluator
GenericRecommenderIRStatsEvaluator)
(org.apache.mahout.cf.taste.impl.model.file FileDataModel)
@pmbauer
pmbauer / y.clj
Created March 5, 2012 22:09
Memoized Y-Combinator
;; Y-combinator
(defn Y [f] ((fn [x] (f (fn [y] ((x x) y))))
(fn [x] (f (fn [y] ((x x) y))))))
;; Y-combinator memoized
(defn Y [f]
(let [c (atom {})
fp-gen (fn [x] (f (fn [y]
(or (@c y)
@pmbauer
pmbauer / recommended_channel_remover.js
Created October 31, 2012 03:39
youtube recommended channel remover
(get-in {:k :v} [:k]) ;; => :v
(update-in {:k :v} [:k] (constantly :x)) ;; => {:k :x}
(get-in {:k :v} []) ;; => {:k :v}
(update-in {:k :v} [] (constantly {:k :x})) ;; => {nil {:k :x}, :k :v}
# wget -O https://gist.github.com/pmbauer/5166100/raw/c72b880ba82dfd598c3cf27a3045833cadec32e2/install_python.sh
# chmod +x install_python.sh
# ./install_python.sh
#!/bin/sh
pushd /usr/local/src
echo " - Install compilers"
yum -y install gcc gdbm-devel readline-devel ncurses-devel zlib-devel bzip2-devel sqlite-devel db4-devel openssl-devel tk-devel bluez-libs-devel make
;; based on my code from test.benchmark
(ns raw-threadring
(:import [java.util.concurrent Exchanger]))
(def ^Exchanger output-pipe (Exchanger.))
(defn relay [state msg]
(if (> msg 0)
(send (:next state) relay (dec msg))