Skip to content

Instantly share code, notes, and snippets.

@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 + '"');
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 / candy.txt
Created November 5, 2014 06:05
Inventory files
Nerds
Tootsie Roll
Rock
Nerds
Skittles
Lollipop
Snickers
Popcorn
Tangy Taffy
Sweet Tarts
@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 / event-offset-polyfill.js
Last active October 2, 2021 18:18
Adds MouseEvent .offsetX and .offsetY to Firefox
// polyfill for event.offsetX/offsetY
// Firefox is the only browser that doesn't support it (IE has since 4)
(function() {
var evt = document.createEvent('MouseEvent');
if (evt.offsetX === void 0) {
Object.defineProperties(MouseEvent.prototype, {
'offsetX': {
get: function() {
return this.layerX - this.target.offsetLeft;
}
@ripter
ripter / common_golf.js
Last active August 4, 2017 18:06
Roll D&D style dice.
// hand golfed the most common dice rolls.
function rnd(max, min) {
return 0| (Math.random() * max) + 0|min;
}
var d20 = rnd.bind(0, 20, 1);
var d8 = rnd.bind(0, 8, 1)
var d6 = rnd.bind(0, 6, 1)
var d4 = rnd.bind(0, 4, 1);
@ripter
ripter / myCollection.js
Created December 19, 2012 15:08
Simple backbone example.
mycompany.Collections.MyCollection = Backbone.Collection.extend({
model: mycompany.Models.MyModel
, url: '/rest/models'
})
@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)
@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 / 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