Skip to content

Instantly share code, notes, and snippets.

@desandro
desandro / jquery-layout-review.md
Created January 28, 2013 18:13
layout thrashing in jQuery
@scottjehl
scottjehl / tmplmeta.md
Created January 25, 2013 18:37
Template meta tag pattern for template-based decisions

I've been finding this little meta[name='tmpl'] pattern useful lately when making template-based decisions in JS, such as when loading a particular file or set of files that are needed only on a particular page of a site.

First, in the HTML of a particular template, like say, a search result page:

<head>
  ...
  <meta name="tmpl" content="searchresult">
</head>
@nzakas
nzakas / type-declarations.js
Created December 14, 2012 22:27
Experiment: Simple way to define types, including prototypal inheritance, in JavaScript
/*
* This is just an experiment. Don't read too much into the fact that these are global variables.
* The basic idea is to combine the two steps of defining a constructor and modifying a prototype
* into just one function call that looks more like traditional classes and other OO languages.
*/
// Utility function
function mixin(receiver, supplier) {
if (Object.getOwnPropertyDescriptor) {
@nicknisi
nicknisi / lint.pre-commit
Created November 12, 2012 15:17
A git pre-commit to check js files up for commit against JSHint. If there are errors, the commit is cancelled.
#!/bin/sh
# JSHint Pre-Commit
# Place this in your .git/hooks/pre-commit directory and rename to `pre-commit`
# expects jshint to be installed in your projects node_modules directory
EXIT_CODE=0
COLOR_RED="\x1B[31m"
COLOR_GREEN="\x1B[32m"
COLOR_NONE="\x1B[0m"
@Wilto
Wilto / hide-and-tel.js
Created July 3, 2012 16:43
Hide and Tel
(function() {
var links = document.getElementsByTagName( "a" );
for ( var i = 0, a = links.length; i < a; i++ ) {
if( links[ i ].href.indexOf( "tel" ) > -1 ) {
var el = links[ i ],
parent = el.parentNode,
num = document.createTextNode( el.innerHTML );
if( el.className.indexOf( "tel" ) === -1 || !parent.className.indexOf( "tel" ) === -1 ) {
@brianboyer
brianboyer / gist:2648545
Created May 9, 2012 20:25
Applescript for PowerMate that resizes a window for responsive web design testing
tell application "System Events"
set frontmostProcess to name of first item of (processes whose frontmost is true)
tell process frontmostProcess
tell window 1
set oldSize to get size
-- change + to - for shrinking
-- change 100 to 5 for fine-tune mode
set newWidth to (item 1 of oldSize) + 100
set size to {newWidth, item 2 of oldSize}
end tell
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@JeffreyWay
JeffreyWay / gist:1525217
Created December 27, 2011 21:29
Instant Server for Current Directory
alias server='open http://localhost:8000 && python -m SimpleHTTPServer'
@tj
tj / app.js
Created December 17, 2011 23:15
express 3.x cookie session middleware example
var express = require('express')
, cookieSessions = require('./cookie-sessions');
var app = express();
app.use(express.cookieParser('manny is cool'));
app.use(cookieSessions('sid'));
app.get('/', function(req, res){
req.session.count = req.session.count || 0;
@mattdsteele
mattdsteele / who_should_i_follow.rb
Created November 24, 2011 05:52
Of the people I follow, who do they follow that I don't follow? (sorted by count of people I follow)
require 'rubygems'
require 'json'
user = ARGV[0]
if user == nil
puts "usage: who-should-i-follow.rb screen_name"
exit 1
end
followers_to_check = 100