Skip to content

Instantly share code, notes, and snippets.

View nathggns's full-sized avatar

Nate Higgins nathggns

View GitHub Profile
@nathggns
nathggns / clamp.js
Created June 25, 2014 14:06
Knockout (2.3+) binding for clamp
define(['knockout', 'clamp'], function(ko, $clamp) {
'use strict';
var textKey = 'originalClampText';
ko.bindingHandlers.clamp = {
update: function(element, valueAccessor, allBindings) {
var defaultText;
@nathggns
nathggns / lisp.js
Last active August 29, 2015 14:02
Lisp Interpreter
var readline = require('readline');
function Scope(variables, parent) {
this.variables = variables || {};
this.parent = parent;
}
Scope.prototype.find = function(name) {
return this.variables.hasOwnProperty(name) ?
this.variables[name] :
interface SomeInterface {
(a : string, b : number, c : boolean) : void
}
function SomeFunction : SomeInterface() {
}
// Would be the same as
@nathggns
nathggns / DeferredObservable.js
Created December 14, 2013 18:18
A type to represent observables where the value of it is in a promise ($.Deferred, Q, etc).
/**
* Just a type to store deferred observables.
*
* When the deferred is resolved, it'll set the value of the observable
* to result of the deferred.
*
* @param {Function} observable The function to use for the
* observable
* @param {$.Deferred} deferred The deferred value
* @param {Boolean} shouldSetObsValue Should we set the value of the
@nathggns
nathggns / str.php
Created November 27, 2013 20:29
Class-representation of strings. Uses arrays internally.
<?php
/**
* Immutable String class that uses arrays to represent
* strings.
*
* Currently useless as we have no unicode friendly way to split a string
* into characters
*
* @todo Find a unicode-friendly way to split strings
@nathggns
nathggns / flag (inline).scss
Created November 22, 2013 14:40
Modification to the flag object to add the ability to make it inline
/*------------------------------------*\
$FLAG
\*------------------------------------*/
.flag {
display: table;
width: 100%;
}
.flag--inline {
/**
* Returns a function that uses it's first argument as the context
* for a callback
* @param {Function} callback The callback to call
* @return {Function}
*/
function context(callback) {
return function() {
var args = Array.prototype.slice.call(arguments);
var context = args.shift() || this;
/**
* Protect a callback based on a condition
* @param {Function} protector The condition to protect with
* @param {Function} protectee The callback to protect
* @param {Boolean} not Should the protector protect using
* true or false results
* @param {mixed} context Optional context to call protector
* and protectee with
* @return {Function} The protected callback
*/
@nathggns
nathggns / jquery.shush.js
Last active December 25, 2015 02:49 — forked from cdl/jquery.shush.js
(function($) {
$.fn.shush = function($btn) {
// First, validation
// Cache global variables
var $form = $(this);
// Default $btn to input[type=submit]
$btn = $btn || 'input[type=submit]';
@nathggns
nathggns / errorception.js
Created September 27, 2013 11:10
Wrap Errorception to provide stack traces in some browsers
window.onerror = (function(old) {
return function() {
var args = [].slice.call(arguments);
for (var i = 0, l = arguments.length; i < l; i++) {
if (args[i] instanceof Error) {
window._errs.push(args[i]);
}