Skip to content

Instantly share code, notes, and snippets.

@skatenerd
skatenerd / gibberish.clj
Created November 21, 2013 02:20
make gibberish
(defn update-the-submap [m word]
(update-in m [word] (fnil inc 0)))
(defn update-the-map [m triplet]
(let [thekey (take 2 triplet)
theval (last triplet)]
(update-in m [thekey] (fnil #(update-the-submap % theval) {}))))
(def thetext '("hello" "world" "dogs" "cats" "computer" "mouse" "hello" "world" "cats" "cats" "dogs" "cats" "food" "hello" "world" "dogs"))
(def offsettext (conj thetext nil))
@skatenerd
skatenerd / therave.rb
Last active December 31, 2015 09:39
First pass at simulating a lightswitch rave with `say`
Process.fork { `say -v Kathy -r 70 #{"who who wa doo doo " * 80}`}
Process.fork { `say -v Ralph -r 40 #{"dum " * 80}`}
Process.fork { `say -v Ralph -r 130 #{"bum dum bum. . . . . . . . . ." * 80}`}
Process.fork { `say -v Bruce -r 130 #{"the system is down " * 80}`}
@skatenerd
skatenerd / euler_60.clj
Last active December 31, 2015 23:19
projecteuler.net/problem=60
(ns euler.60
(:use euler.prime))
(defn- crude-log [target base]
(let [raises (iterate #(* base %) 1)]
(first (keep-indexed #(if (> %2 target) %1) raises))))
(defn pairs [unique-elements]
(set (for [first-element unique-elements
second-element unique-elements
(ns euler.61
(:use euler.prime
euler.dfs
))
(def naturals (iterate inc 1))
(defn map-naturals [generator]
(map generator naturals))
@skatenerd
skatenerd / whatwillhappen.clj
Created January 8, 2014 04:43
what will happen?
(defn square [x] (* x x))
(defprotocol Squarable (square [this]))
(defrecord SquareRoot [x]
Squarable
(square [this] x))
(square 4)
(square SquareRoot. 5)
@skatenerd
skatenerd / challenge.clj
Created January 9, 2014 04:25
Solution to the telephone number search problem
(ns euler.challenge
(:use euler.dfs))
(def numbers-to-letters
{2 ["a" "b" "c"]
3 ["d" "e" "f"]
4 ["g" "h" "i"]
5 ["j" "k" "l"]
6 ["m" "n" "o"]
7 ["p" "q" "r" "s"]
@skatenerd
skatenerd / dfs.clj
Last active January 2, 2016 23:39
dfs without repetition through a graph
(def grapph {
;some stuff
})
(defn neighbors [node]
(get graph node))
(defn dft [node visited-so-far]
(let [new-visited-so-far (set (conj visited-so-far node))
unvisited-children (set (remove visited-so-far (set (neighbors node))))
# This is a combination of 12 commits.
# The first commit's message is:
more tinker
# This is the 2nd commit message:
more tinker
# This is the 3rd commit message:
@skatenerd
skatenerd / gist:8583106
Created January 23, 2014 17:35
format date
(import 'java.text.SimpleDateFormat)
(def date-format (SimpleDateFormat. "HH:mm:ss"))
(def parsed (.parse date-format "10:22:00"))
(.toString parsed)
; ---> "Thu Jan 01 10:22:00 CST 1970"
@skatenerd
skatenerd / wat.py
Last active January 4, 2016 13:08
lol
import sys
def foo(i):
sys.setrecursionlimit(i+5)
print(i)
foo(i+1)