Skip to content

Instantly share code, notes, and snippets.

View thunklife's full-sized avatar

Jesse Williamson thunklife

View GitHub Profile
@thunklife
thunklife / packages.el
Created July 6, 2015 21:33
elm-mode for Spacemacs
;;; packages.el --- elm Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <[email protected]>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
@thunklife
thunklife / continuation.js
Created December 12, 2014 19:14
Continuation Monad
console.log("\033[39mRunning tests…");
function assertEquals(actual, expected, description) {
if(typeof(actual) === "undefined") {
console.error("\033[31m" + description + " not implemented\033[39m");
} else {
if(actual !== expected) {
console.error("\033[31m" + description + " failed, expected " + expected + ", got " + actual + "\033[39m");
} else {
console.log(description + " \033[32m ok\033[39m");
}
@thunklife
thunklife / dreamCars.js
Last active August 29, 2015 14:02
Dream Cars
module.exports = dreamCars = [
{
make: "Aston Martin",
model: "DB9"
},
{
make: "Lotus",
model: "Elise"
},
{
@thunklife
thunklife / size-of-closure.js
Created March 13, 2014 16:57
In "New Rules for JavaScript", Kyle Simpson points out that the anonymous functions used as click handlers are "bloated" closures...
(function IIFE(){
function init(){
var something = "cool",
somethingElse = [1,2,3,4,5,6,7,8],
$btn1 = $("btn1"),
$btn2 = $("btn2"),
$btn3 = $("btn3");
$btn1.click(function hander(evt){
console.log("1", something);
@thunklife
thunklife / index.js
Created January 16, 2014 15:33
requirebin sketch
// hello world
var curry = require('fn-curry');
var conditional = curry(function(pred, succ, fail){
return function(){
var args = Array.prototype.slice.call(arguments);
return pred.call(this, args) ? succ.apply(this, args) : fail.apply(this, args);
};
});
var even = function (i){
@thunklife
thunklife / funkshun.js
Created December 18, 2013 21:57
Some recursive functions...for learning.
var funkshun = (function(){
var concat = Array.prototype.concat;
function replicate(n, x){
return n===0 ? [] : concat.call(replicate(--n, x),x);
}
function take(n, arr){
function _take(n, arr){
var head;
@thunklife
thunklife / fizzBuzz.hs
Created October 9, 2013 16:00
A newbie's attempt at FizzBuzz as a list comprehension in Haskell.
fizzBuzz :: [Integer] -> [String]
fizzBuzz list = [if mod el 15 == 0 then "FIZZBUZZ" else if mod el 3 == 0 then "FIZZ" else if mod el 5 == 0 then "BUZZ" else show el | el <- list]
@thunklife
thunklife / twinks
Last active December 24, 2015 00:39
Replaces the t.co URL in twitter links (twinks, get it?) with the expanded one because my work proxy blocks t.co
//Because I read twitter at work
//Because we have a proxy that blocks t.co but not twitter.com
//Because I have rewritten this from scratch more than once and not saved it
//I'm keeping this here.
//Paste into bookmarklet, run when I open twitter, be happy.
javascript:(function(){$(document).on("hover","a.twitter-timeline-link",null,function(){var $this = $(this), xUrl = $this.attr("data-expanded-url"); $this.attr("href", xUrl);});})();
@thunklife
thunklife / chaining.js
Created April 15, 2013 17:26
Something I stumbled upon for method chaining...along the lines of an Expression Builder, but without a named object.
//So, I came up with this when playing with an idea for a configuration DSL. It's like Expression Builders...I think.
//I think it's really like Partial Application with named functions.
//But is it rubbish?
//This is a contrived example for addition
var add = function(x){
//Right here is the basic pattern.
//Rather than return a function, return and object with a named function so your chaining becomes more grammatical
return{
to: function(y){
return x + y;
@thunklife
thunklife / fubuerror
Created March 2, 2013 23:51
What is this...I don't even...
Source Error:
Line 15: protected void Application_Start(object sender, EventArgs e)
Line 16: {
Line 17: FubuApplication.DefaultPolicies().StructureMapObjectFactory().Bootstrap();
Line 18:
Line 19: }
Source File: c:\Users\Jesse\Documents\Projects\FubuValidation\FubuValidation\Global.asax.cs Line: 17