Skip to content

Instantly share code, notes, and snippets.

@ship561
ship561 / gist:616809eea6293f915b86
Last active August 29, 2015 14:06
Example of reducers/fold hanging when the input is a hashmap
(let [sqs {"AUGUGGAAAG" 4, "CGACCUCGUC" 2, "CCAGCGAACC" 2, "GGGCGAAGCU" 5, "GUUUACUUCA" 1,
"UACCAUAGUA" 1, "CGACCAGCAU" 2, "UGAAUUUCGA" 2, "GGUCUUUCUU" 2, "UGAAAUACAU" 1}]
(prn :>>)
(r/fold (fn ([] {})
([l r] (merge-with + l r)))
(fn [M sq cs]
(->> (take 2 sq)
frequencies
(merge-with + M)))
sqs))
(-> (identity 12)
((fn [the-threaded-var] (* the-threaded-var 3)))
(/ 3))
@ship561
ship561 / 0_reuse_code.js
Created October 7, 2015 17:52
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
(defn bar [input]
(let [xf1 (partial re-seq #"[-\w]+")
xf2 (fn [[x & ys]]
[x
(->> ys
(map-indexed #(if (odd? %1)
(read-string %2)
%2))
(apply assoc {}))])]
(transduce (comp (map xf1)
@ship561
ship561 / gist:cbc8d099348a00a38b43
Created March 3, 2016 22:51
Levenshtein distance that short circuits
(defn levenshtein [thr str1 str2]
"Clojure Levenshtein distance which short circuits when the distance is > thr"
(let [n (count str1)
m (count str2)]
(cond
(= 0 n) m
(= 0 m) n
:else
(last
(reduce (fn [prev-col i]
(ns sandbox.cipher
(:require [clojure.string :as str]))
(def alphabet "abcdefghijklmnopqrstuvwxyz")
(defn rotate [n coll]
(concat (drop n coll) (take n coll)))
(defn caeser-cipher [offset]
(-> (zipmap alphabet (rotate offset alphabet))