Skip to content

Instantly share code, notes, and snippets.

@erikeldridge
erikeldridge / log1.js
Created Apr 16, 2011
A cross-browser logging util
View log1.js
/**
* Cross-browser logging utils
*
* This fn differs from something like the jQuery log plugin in that
* it returns console.log, if avail, instead of calling it. This allows
* us to call it in file with the log statement, which means that the
* line # and file name displayed are more helpful. This isn't supposed
* to be a logging framework like blackbird or log4javascript.
*
* Usage: var msg = 'foo'; log(msg).call(console, msg)
View toolkit.markdown

Tips & Tools

Ack

  • Use less for paging, but still provide ack's nice colored output and per-file grouping, by adding this to .ackrc: --pager=less -r -E

JS

  • inheritance patterns: prototypal/classical/pseudo-classical/hacked-classical/functional
  • class frameworks:
@erikeldridge
erikeldridge / gist:899306
Created Apr 2, 2011
handy code for creating OAuth access token in Sinatra
View gist:899306
# ....
get '/start' do
consumer = OAuth::Consumer.new( ENV['OAUTH_KEY'], ENV['OAUTH_SECRET'], {
:site => "https://api.twitter.com",
:request_token_path => '/oauth/request_token'
})
request_token = consumer.get_request_token({:oauth_callback => ENV['OAUTH_CALLBACK']})
response.set_cookie( "oauth_request_token", request_token.params['oauth_token_secret'] )
redirect request_token.authorize_url
end
@erikeldridge
erikeldridge / gist:873978
Created Mar 17, 2011
Playing with prototypal inheritance in JavaScript
View gist:873978
// I'm not sure what this is supposed to be demonstrating,
// but I think it's worth noting that flashyBlueBtn contains
// color & effect attributes event though we say
// FlashyBlueButton.prototype = blueBtn.
function Button(color){
this.color = color;
}
var blueBtn = new Button('blue');
@erikeldridge
erikeldridge / gist:873948
Created Mar 17, 2011
Douglas Crockford's object creation method
View gist:873948
// Credit: http://javascript.crockford.com/prototypal.html
if (typeof Object.create !== 'function') {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
newObject = Object.create(oldObje
View config.ru
require 'router'
use Rack::CommonLogger
use Rack::ShowExceptions
use Rack::Lint
use Rack::Static, :urls => ["/static"]
run Router.new
View .vimrc
" use 4-space soft tabs
" http://vim.wikia.com/wiki/Indenting_source_code
set expandtab
set shiftwidth=4
set softtabstop=4
" turn on auto-indent
" Note: to auto-indent a whole file, run: gg=G
set autoindent
@erikeldridge
erikeldridge / autotest.watchr
Created Dec 13, 2010
files for auto-running yet tests
View autotest.watchr
# Watchr script used in http://erikeldridge.wordpress.com/2010/12/13/running-yeti-tests-automatically-with-watchr/
# watch for changes in test files
watch( 'test/test_.*\.html' ) { |md|
system('clear');
system("yeti #{md[0]}")
}
# watch for changes in lib files
watch( 'lib/(.*)\.js' ) { |md|
system('clear');
View github_tree_slider.js
GitHub.TreeSlider = function () {
if (window.history && window.history.pushState) {
function a() {
if (e.sliding) {
e.sliding = false;
$(".frame-right").hide();
$(".frame-loading:visible").removeClass("frame-loading")
}
}
if (!($("#slider").length == 0 || !GitHub.shouldSlide)) if (!navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
@erikeldridge
erikeldridge / demo.html
Created Oct 11, 2010
A simple YUI 3 module for adding Yahoo! login to a page
View demo.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<!-- Licensed under Yahoo! BSD license http://gist.github.com/375593 -->
</head>
<body>
<span id="login"></span>