Skip to content

Instantly share code, notes, and snippets.

@erikeldridge
erikeldridge / log1.js
Created April 16, 2011 08:49
A cross-browser logging util
/**
* 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)

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 April 2, 2011 07:24
handy code for creating OAuth access token in Sinatra
# ....
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 March 17, 2011 07:40
Playing with prototypal inheritance in JavaScript
// 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 March 17, 2011 07:01
Douglas Crockford's object creation method
// 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
require 'router'
use Rack::CommonLogger
use Rack::ShowExceptions
use Rack::Lint
use Rack::Static, :urls => ["/static"]
run Router.new
@erikeldridge
erikeldridge / .vimrc
Created December 24, 2010 08:13
my .vimrc file
" 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 December 13, 2010 06:55
files for auto-running yet tests
# 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');
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 October 11, 2010 03:59
A simple YUI 3 module for adding Yahoo! login to a page
<!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>