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
async.waterfall [
(cb) -> doStuff(cb)
(result, cb) -> doOtherStuff(result, cb)
(someOtherResult, cb) -> finally(someOtherResult, cb)
], (err, res) ->
console.log 'res is', res
# ᕕ( ᐛ )ᕗ WELP
async.waterfall [
React.renderComponent(
<MomentPreviewList data={previewList}/>,
document.getElementById('moment-live-feed')
)
@jergason
jergason / makeN.js
Created May 23, 2014 17:22
A use for the Array() constructor!
function makeN(n, obj) {
// gotta use .apply(null) because Array(n) makes a new empty array of size n and map behaves starngely
// Array.apply(null, Array(n)) creates an array of size n with undefined as the value of every item
// we can then call map on it to get back an array with n `obj`s.
return Array.apply(null, Array(n)).map(function() { return obj; });
}
@jergason
jergason / foo.jsx
Last active August 29, 2015 14:06 — forked from fivetanley/foo.html
/** @jsx: React.DOM */
var React = require('react');
var IfThingy = React.createClass({
render: function() {
var ifThingy;
if (this.props.someVar) {
ifThingy = <h1>Some Var Is {this.props.someVar}</h1>;
}
else {
@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
@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 / 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>
(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 / 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.
@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