Skip to content

Instantly share code, notes, and snippets.

View eliperelman's full-sized avatar

Eli Perelman eliperelman

View GitHub Profile
@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 ) {
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 / 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) {
@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 / 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 / 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 / index.html
Created November 2, 2011 03:23
jQuery Deferreds and Promises Demo
<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Deferreds and Promises</title>
</head>
<body>
<div class="container">
<form method="get" action="http://search.twitter.com/search.json">
<input type="search" class="search">
<input type="submit" value="Search teh Tweets!" class="submit">
@eliperelman
eliperelman / LICENSE.txt
Created August 16, 2011 06:09 — forked from 140bytes/LICENSE.txt
Throttling and Debouncing
DO WHAT THE **** YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Eli Perelman <http://eliperelman.com>
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 **** YOU WANT TO PUBLIC LICENSE
@eliperelman
eliperelman / example.js
Created July 6, 2011 04:11
Revealing Module pattern
var App = (function() {
var module1 = {
method1: function() {
// code here
}
};
var module2 = {
ajax: $.ajax
@eliperelman
eliperelman / example.js
Created July 6, 2011 04:08
Module/Namespacing/Singleton pattern
var Namespace = {};
Namespace.module1 = {
method1: function() {
// code here
}
};
Namespace.module2 = {
method2: function() {