Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / ba-whatevcache.js
Created November 1, 2010 17:17
whatevCache: a simple localStorage-if-you-got-it, otherwise not-at-all-persistent data object cache.
/*!
* JavaScript whatevCache - v0.2pre - 12/30/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// whatevCache.set( key, value [, ttl ] );
@gf3
gf3 / git-feature
Created May 3, 2011 22:45
Git Feature Command – Feature Branches
#!/usr/bin/env zsh
# git-feature
# Written by: Gianni Chiappetta <gianni@runlevel6.org>
# Requires: git 1.7.5+, zsh 4.3.11+
# Screenshot: http://cloud.gf3.ca/6TPb
function c_list { echo " \033[1;32m✔\033[0m $1"; }
function e_list { echo " \033[1;31m✖\033[0m $1"; }
@ryanseddon
ryanseddon / LICENSE.txt
Created June 6, 2011 04:51 — forked from 140bytes/LICENSE.txt
select DOM elements by any valid CSS selector
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
@abozhilov
abozhilov / gist:1333507
Created November 2, 2011 12:32
Arguments default value
function func(a, f) {
return function (args) {
args.__proto__ = a;
f.call(this, args);
};
};
var f = func({foo : 10, bar : 20}, function (args) {
print(args.foo, args.bar);
@cowboy
cowboy / iife-variations.js
Created December 24, 2010 00:14
A few variations on writing an IIFE
// Want to learn more about Immediately Invoked Function Expressions? Read
// this article first:
//
// http://benalman.com/news/2010/11/immediately-invoked-function-expression/
// Parens are used to tell the parser that it's a function expression,
// not a function declaration. If you don't explicitly tell the parser to
// expect an expression, it will throw a SyntaxError exception because it
// sees a function declaration without a name specified.
@jonathantneal
jonathantneal / templatejs.js
Created January 21, 2012 07:23
templatejs.js
// TemplateJS v3.1.1 MIT/GPL2 @jon_neal
(function (global) {
function escapeJS (str) {
return str.replace(/"/g, '\\"').replace(/\n/g, '\\n').replace(/\r/g, '\\r');
}
function TemplateWalk (str, chars, helpers, instance) {
// check for the opening delimiters and init our array buffer
var index = str.indexOf(chars.START_PROP), buffer = '', helper;
// find out what prefix this browser supports.
// usage: gimmePrefix('transform') // 'WebkitTransform'
// returns false if unsupported.
function gimmePrefix(prop){
var prefixes = ['Moz','Khtml','Webkit','O','ms'],
elem = document.createElement('div'),
upper = prop.charAt(0).toUpperCase() + prop.slice(1);
@gf3
gf3 / ago.js
Created June 2, 2011 18:43
Super small relative dates
module.exports = (function(){
const MS =
{ seconds: 1000
, minutes: 60 * 1000
, hours: 60 * 60 * 1000
, days: 24 * 60 * 60 * 1000
, weeks: 7 * 24 * 60 * 60 * 1000
, months: 30 * 7 * 24 * 60 * 60 * 1000
, years: 365 * 24 * 60 * 60 * 1000 }
@pjkix
pjkix / css-stats-ack.sh
Created October 5, 2011 21:39
shell script to generate some css file statistics
#!/bin/bash
## v1.0.6
## this script will gernerate css stats
### example output
# CSS STATS
# ----------
# Floats: 132
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Responsive Design Testing</title>
<style>
body { margin: 20px; font-family: sans-serif; overflow-x: scroll; }
.wrapper { width: 6000px; }
.frame { float: left; }
h2 { margin: 0 0 5px 0; }