Skip to content

Instantly share code, notes, and snippets.

@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:2786033
Created May 25, 2012 05:49
Compose Method, Functional JavaScript

#What is a compose method? Compose takes a series of single parameter functions that are used as the parameters for the previous functions. The last function can take any number of parameters.

Code example:

function text(a) {
    return 'item: ' + a;
}
function hello(a) {
    return 'Hello ' + a;
@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.');
}
@ripter
ripter / General.markdown
Created September 10, 2012 19:26
JavaScript Test

General

  • What JS libraries have you used?
    • Why that over X?
  • What JS tempting libraries have you used?
  • How do you organize your code?
  • Have you used CoffeeScript?
    • What do you like/dislike about it?
    • Advantages/Disadvantages over JavaScript?
@ripter
ripter / gist:4270799
Created December 12, 2012 19:29 — forked from hashmal/gist:874792
Added check for boolean.
-- Print contents of `tbl`, with indentation.
-- `indent` sets the initial level of indentation.
function tprint (tbl, indent)
if not indent then indent = 0 end
for k, v in pairs(tbl) do
formatting = string.rep(" ", indent) .. k .. ": "
if type(v) == "table" then
print(formatting)
tprint(v, indent+1)
elseif type(v) == 'boolean' then
@ripter
ripter / SpriteSheet.lua
Created December 13, 2012 05:02
Zwoptex template for Löve2D
-- SpriteSheet
-- Handles custom Zwoptex template: https://gist.github.com/4274146
module('SpriteSheet', package.seeall)
local SpriteSheet = {}
-- Loads and creates the sprite sheet from sheetName
function SpriteSheet:new(sheetName)
local ss = require(sheetName)
setmetatable(ss, { __index = self })
@ripter
ripter / AnimSheet.lua
Created December 14, 2012 17:14
AnimationSheet for Löve2D and Zwoptex.
--[[
Animation Sheet
Allows you to set up several animations from a single animation sheet and play them.
This wil only play one animation at a time.
By Chris Richards
--]]
module('AnimSheet', package.seeall)