Skip to content

Instantly share code, notes, and snippets.

View thunklife's full-sized avatar

Jesse Williamson thunklife

View GitHub Profile
@thunklife
thunklife / callingcode.js
Last active December 11, 2015 07:48
Idea to configure which events to bind FubuValidation to.
//The thing I don't like about this approach is you would need to include this or validation totally dies.
//Maybe that's not so bad? Maybe you want to do it differently on each page?
//Specific events
(function() { bindValidation(["focusout", "keydown"]); }());
//Default events
(function() { bindValidation([]); }());
@thunklife
thunklife / ValidationActivator.js
Last active December 11, 2015 08:08
Another spike for declaring client-side validation bindings
$(document).ready(function () {
$('form.validated-form').each(function () {
var mode = $(this).data('validationMode');
$(this).validate({
ajax: mode == 'ajax',
continuationSuccess: function (continuation) {
continuation.form.trigger('validation:success', continuation);
},
bindingConfiguration: {
//bindings is an array of selectors and corresponding events
@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
@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 / 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 / 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 / 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 / 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 / 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 / dreamCars.js
Last active August 29, 2015 14:02
Dream Cars
module.exports = dreamCars = [
{
make: "Aston Martin",
model: "DB9"
},
{
make: "Lotus",
model: "Elise"
},
{