Skip to content

Instantly share code, notes, and snippets.

View eliperelman's full-sized avatar

Eli Perelman eliperelman

View GitHub Profile
@eliperelman
eliperelman / gist:1390043
Created November 23, 2011 21:57 — forked from garth/gist:1388969
Convert url image ref into inline base 64 in css with nodejs
var css = 'insert lots of css here';
var files = {};
css = css.replace(/url\((\S*)\.(png|jpg|jpeg|gif)\)/g, function(match, file, type)
{
var fileName = file + '.' + type;
var base64 = fs.readFileSync(fileName).toString('base64');
if (typeof(files[fileName]) !== 'undefined') {
console.log('Warning: ' + fileName + ' has already been base64 encoded in the css');
}
@eliperelman
eliperelman / HttpError.js
Created January 5, 2012 16:57 — forked from unscriptable/HttpError.js
Example "subclass" of Error object
define(function () {
var HttpError = function (msg, code) {
var ex = new Error(msg || 'Unknown HTTP error');
ex.code = code;
ex.toString = function() {
return 'Error: '
+ (this.code ? '' : '(' + this.code + ') ')
+ this.message;
};
@eliperelman
eliperelman / index.html
Created January 18, 2012 22:04 — forked from JeffreyWay/legacy.js
Legacy JS
<!doctype html>
<html>
<head></head>
<body>
<ul>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
</ul>
@eliperelman
eliperelman / lazy_parse_int.js
Created February 3, 2012 16:58 — forked from nathansmith/parseint.js
Makes parseInt have default radix of 10.
// JSLint:
/*global window, parseInt*/
// Conditionally check value, in case
// future implementations of parseInt
// provide native base-10 by default.
(function () {
var _parseInt = window.parseInt;
if (_parseInt('09') === 0) {
person.eat(food, function() {
if (typeof food === 'tacobell') {
// Kinda yum...
setInterval(function() {
// Oh noes!
// http://www.hulu.com/watch/10304/saturday-night-live-colon-blow
colon.blow();
}, 120000); // 2 hrs.
}
});
@eliperelman
eliperelman / guidelines.md
Last active October 1, 2015 18:18
Front end guidelines
// Do not use document.write, use DOM access instead
$( '#element' ).append(' <div>text</div>' );

// Incorrect
document.write('<div>text</div>');

// Use feature detection, not browser/User-Agent sniffing
if ( document.addEventListener ) {
@eliperelman
eliperelman / laws.md
Last active August 2, 2016 05:48
appendTo Laws of Skype

Whitbeck’s Law

If it exists, there is a GIF of it.

Manor’s Law

For every message there is an equal and opposite deletion.

Cowart’s Law

All great messages will be deleted before you have a chance to read them.

Neiner’s Law

function deferredRequest( resource, data ) {
return $.Deferred(function( dfd ) {
amplify.request({
resourceId: resource,
data: data,
success: dfd.resolve,
error: dfd.reject
});
}).promise();
}
@eliperelman
eliperelman / .gitconfig
Created September 11, 2012 16:18
git ignore command
[alias]
ignore = "!i() { echo $1 >> .gitignore; }; i"
@eliperelman
eliperelman / compose.js
Created September 13, 2012 21:48
Recursive function composition
var compose = function () {
var args = arguments;
return function () {
var funcs = [].slice.call(args);
return (function x(value) {
var current = funcs.pop();
return current ? x(current(value)) : value;