Skip to content

Instantly share code, notes, and snippets.

(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))
@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]
(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 / 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
(-> (identity 12)
((fn [the-threaded-var] (* the-threaded-var 3)))
(/ 3))
@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))
(ns mysql-test
(:require [clojure.java.jdbc :as jdbc])
(:use [edu.bc.bio.sequtils.files]))
(def mysql-ds
{:classname "com.mysql.jdbc.Driver"
:subprotocol "mysql"
@ship561
ship561 / gist:d6ad262c26369f3e6679
Created June 5, 2014 15:43
Some examples using Sqlingvo and korma with clojure.java.jdbc to create a table and execute queries
(require '[clojure.java.jdbc :as jdbc]
'[korma.db :as kdb]
'[korma.core :as kcore]
'[sqlingvo.core :as sql]
'[sqlingvo.vendor :as v]))
;;;examples here are directly from the sqlingvo, jdbc, korma websites
;;;in order to provide a concrete example of using a SQL DSL with jdbc
;;;to execute mysql commands
@ship561
ship561 / sudoku.clj
Created September 20, 2012 13:22
sudoku solver in clojure
(ns sudoku
(:require [clojure.contrib.io :as io]
[clojure.contrib.string :as str]
[clojure.set :as sets]))
;;;example input for testing
(def grid01
(list "003020600"
"900305001"
"001806400"
@ship561
ship561 / init.el
Last active February 26, 2021 18:31
init file for my emacs setup
;;; init.el --- Where all the magic begins
;;
;; Part of the Emacs Starter Kit
;;
;; This is the first thing to get loaded.
;;
;; "Emacs outshines all other editing software in approximately the
;; same way that the noonday sun does the stars. It is not just bigger
;; and brighter; it simply makes everything else vanish."
;; -Neal Stephenson, "In the Beginning was the Command Line"