Skip to content

Instantly share code, notes, and snippets.

@ripter
ripter / createElm.js
Created October 29, 2014 22:00
helper to quickly create elements on the document
// helper to quickly create elements on the document
function createElm(doc, type, props, attributes) {
props = props || {};
attributes = attributes || {};
var elm = doc.createElement(type);
var keys = Object.keys(props);
// props are set directly on the elm
keys.forEach(function(key) {
elm[key] = props[key];
@ripter
ripter / candy.txt
Created November 5, 2014 06:05
Inventory files
Nerds
Tootsie Roll
Rock
Nerds
Skittles
Lollipop
Snickers
Popcorn
Tangy Taffy
Sweet Tarts
09#65#21
06#72#03
Dec 26, 75
Jul 13, 07
Nov 21, 14
15*10*1981
13*02*1992
10#51#16
1964-01-10
06*04*1965
@ripter
ripter / semver.js
Created January 30, 2015 18:44
makeshift semantic version comparison
// makeshift semantic version comparisons
// standard compareFunction
// Checks if semver a is greater than semver b
function gtSemver(a, b) {
// validate
if (!a && !b) { return 0; }
if (!a) { return -1; }
if (!b) { return 1; }
if (!_.isString(a) || !_.isString(b)) {
throw new Error('Semver not valid "' + a + '", "' + b + '"');
@ripter
ripter / processTemplate.js
Created April 24, 2015 03:15
Command line tool to process a lodash/underscore template.
#!/usr/bin/env node
/*global require, process */
'use strict';
var fs = require('fs');
var _ = require('lodash');
var Q = require('q');
var program = require('commander');
var readFile = Q.denodeify(fs.readFile);
@ripter
ripter / LICENSE.txt
Created June 27, 2011 15:43 — forked from 140bytes/LICENSE.txt
Set date to the first day of the week
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@ripter
ripter / gist:2772039
Created May 22, 2012 22:25
Notes from Html5 Dev Conf on May 21st 2012 SF.

I ordered these by quality/usefulness, so if you don't read the whole thing you probably didn't miss much.

#What would crockford do?

Revoke all software patents. Would like to have.

##Yahoo's problems

Yahoo was dishonest and started becoming a patent troll. This why he left yahoo for PayPal.

@ripter
ripter / gist:2773531
Created May 23, 2012 06:25
Partial method

Underscore supports partials with _.bind(), the only downside is that you have to always pass this. So I wanted to see how hard it would be to create my own version of partial.

This is of course a silly exercise, ECMAScript 5th Edition provides a fun.bind() method that _.bind() will use that if you have at least IE 9. I just find always passing the this parameter ugly and from my understanding of functional programming you shouldn't be using this in a partial anyways.

##Here is my first attempt.

var partial = function(){ var args = Array.prototype.slice.call(arguments), fn = args.shift(); return function(){ return fn.apply(fn, args.concat(Array.prototype.slice.call(arguments) )); }}
@ripter
ripter / gist:2785877
Created May 25, 2012 05:11
Curry Method

#What is the difference between Curry and Partial? This seems like a confusing topic for a lot of people. I actually had a really hard time trying to understand the difference between the two. A lot of people think they are the same thing, or that currying is just a special form of partial application.

##So what is currying? When you curry a function, it returns a function that calls another function for every parameter. Currying creates a series of single parameter functions. Some code examples should clear this up.

@ripter
ripter / gist:3493456
Created August 27, 2012 23:44
Number formatter
function formatNumber(num) {
var thousands = ',';
var decimal = '.';
var numStr = '' + num;
var formatted = '';
if (typeof num !== 'number') {
throw new Error('Must pass a number, received "' + num + '" instead.');
}