Skip to content

Instantly share code, notes, and snippets.

View rcherny's full-sized avatar

Rob Cherny rcherny

View GitHub Profile
@rcherny
rcherny / global-variables-are-bad.js
Created May 25, 2012 11:54 — forked from hallettj/global-variables-are-bad.js
How and why to avoid global variables in JavaScript
// It is important to declare your variables.
(function() {
var foo = 'Hello, world!';
print(foo); //=> Hello, world!
})();
// Because if you don't, the become global variables.
(function() {
@rcherny
rcherny / uppercase-command.js
Created June 5, 2012 17:24 — forked from desandro/uppercase-command.js
To uppercase TextMate node command
#!/usr/bin/env node
process.stdin.resume();
var str = '';
process.stdin.on( 'data', function ( chunk ) {
str += chunk;
});
@rcherny
rcherny / gist:2945695
Created June 17, 2012 20:43 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@rcherny
rcherny / gist:3098217
Created July 12, 2012 13:52 — forked from rmurphey/gist:3086328
What's wrong with Netmag's "Optimize your JavaScript" post

What's wrong with Netmag's "Optimize your JavaScript" post

Update: The original post on Netmag has been updated since this was written.

I tweeted earlier that this should be retracted. Generally, these performance-related articles are essentially little more than linkbait -- there are perhaps an infinite number of things you should do to improve a page's performance before worrying about the purported perf hit of multiplication vs. division -- but this post went further than most in this genre: it offered patently inaccurate and misleading advice.

Here are a few examples, assembled by some people who actually know what they're talking about (largely Rick Waldron and Ben Alman, with some help from myself and several others from the place that shall be unnamed).

Things that are just plain wrong

@rcherny
rcherny / build.js
Created July 15, 2012 00:19 — forked from millermedeiros/build.js
sample node.js build script including RequireJS optimizer (r.js) and copy/delete/filter files
var _cli = require('commander'),
_glob = require('glob'),
_minimatch = require('minimatch'),
_wrench = require('wrench'),
_fs = require('fs'),
_path = require('path'),
_requirejs = require('requirejs');
@rcherny
rcherny / compact_expand_css_command.py
Created July 30, 2012 20:32 — forked from vitaLee/compact_expand_css_command.py
SublimeText command for compacting/expanding CSS rules
import sublime
import sublime_plugin
import re
class CompactExpandCssCommand(sublime_plugin.TextCommand):
def run(self, edit, action='compact'):
rule_starts = self.view.find_all('\{')
rule_ends = self.view.find_all('\}')
@rcherny
rcherny / _pems.scss
Created August 7, 2012 20:07 — forked from mrdanadams/_pems.scss
PX to EMs conversion in Sass
/* See http://mrdanadams.com/2012/pixel-ems-css-conversion-sass-mixin/ */
/* Default font size in pixels if not overridden. */
$baseFontSize: 16;
/* Convert PX units to EMs.
Ex: margin-right: pem(16);
*/
@function pem($pxval, $base: $baseFontSize) {
@return #{$pxval / $base}em;
@rcherny
rcherny / toggle-no-js-html-flag
Created August 23, 2012 20:59
Toggle "no-js" on <html> element using JavaScript and Underscore (no jQuery)
// REQUIRES UNDERSCORE.JS but could be redone without fairly easily
// NO jQuery here though ...
var setJSFlag = (function(){
var htmlEl = document.getElementsByTagName('html')[0];
var classNames = htmlEl.className.split(' ');
var classFlags = [];
function setFlag(){
if (classNames.length > 0) {
@rcherny
rcherny / gist:3557376
Created August 31, 2012 18:57 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt