Skip to content

Instantly share code, notes, and snippets.

View jergason's full-sized avatar
🦢
theft puts a parade in my walk

Jamison Dance jergason

🦢
theft puts a parade in my walk
View GitHub Profile
@jergason
jergason / start_tmux
Created February 23, 2015 17:42
tmux start script
tmux new-session -s kuali -n cm-proto -d
tmux send-keys -t kuali 'cd cm-prototype' C-m
tmux split-window -v -p 20 -t kuali
tmux select-layout -t kuali main-vertical
tmux send-keys -t kuali:cm-proto.0 'vim .' C-m
tmux send-keys -t kuali:cm-proto.1 'cd cm-prototype && npm run hmr' C-m
tmux resize-pane -Z -t kuali:cm-proto.0
tmux attach -t kuali
{-# LANGUAGE DeriveGeneric #}
data User = User {
id :: String,
email :: String,
hash :: String,
institutionId :: String
} deriving (Show, Generic)
data UserPrintable = UserPrintable {
@jergason
jergason / generators.js
Created December 11, 2014 16:47
generators
function* generator() {
yield 1;
yield 2;
yield 3;
yield 4;
}
var i = generator();
var next = {};
while (!next.done) {
@jergason
jergason / quicksort.js
Created November 23, 2014 15:37
quicksort in js
function quicksort(list) {
if (list.length == 0) {
return list;
}
var pivot = list.splice(Math.floor(list.length / 2), 1)[0];
var smaller = quicksort(list.filter(function(i) {
return i <= pivot;
}));
var larger = quicksort(list.filter(function(i) {
@jergason
jergason / quicksort.hs
Created November 23, 2014 15:28
quicksort in haskell
-- see http://learnyouahaskell.com/recursion#quick-sort
quicksort' :: (Ord a) => [a] -> [a]
quicksort' [] = []
quicksort' (x:xs) =
let biggerSorted = quicksort' [a | a <- xs, a > x]
smallerSorted = quicksort' [a | a <- xs, a <= x]
in smallerSorted ++ [x] ++ biggerSorted
@jergason
jergason / wat.hs
Created November 12, 2014 18:55
what am i even doing
f :: Int -> [Int] -> [Int]
f n arr = -- Complete this function
concat $ map (makeN n) arr
makeN :: Int -> (Int -> [Int])
makeN n =
(\x -> map (\i -> x) [1..n])
-- This part handles the Input and Output and can be used as it is. Do not modify this part.
(defn products-of-ints [nums]
"Takes an array of integers and returns an array of integers where the
element at each index is the product of all the other elements except the
element at that index multiplied."
(let [product-of-every-num (reduce * nums)]
(map #(/ product-of-every-num %) nums)))
@jergason
jergason / app.jsx
Created October 29, 2014 21:08
cursors woooo
var React = require('react');
var History = require('immutable-history');
// call `render` whenever the cursor changes
var state = new History({posts: [], username: 'Jamitron The Terrible'}, render);
var App = React.createClass({
render: function() {
var postsCursor = this.props.data.cursor(['posts']);
return <div>
@jergason
jergason / permutations.clj
Created October 20, 2014 16:54
horribly awful clojure code
(defn decrement-char-count [char-map character]
(let [new-char-map (assoc char-map character (dec (get char-map character 0)))]
[(new-char-map character) new-char-map]))
(defn make-char-map [string]
(reduce (fn [char-map character] (assoc char-map character (inc (get char-map character 0)))) {} (seq string)))
(defn permutation? [str1 str2]
"return true if str2 can be formed by some permutation of str1, false otherwise"
(let [str1-map (make-char-map str1)]
@jergason
jergason / handler.clj
Created October 12, 2014 15:16
compojure example
(ns durp.handler
(:require [compojure.core :as cc]
[compojure.handler :as handler]
[ring.util.response :refer [response]]
[ring.middleware.json :as json]))
(cc/defroutes app-routes
(cc/POST "/user/:user-id" [user-id {:body body}] (response (body))))
(def app