Skip to content

Instantly share code, notes, and snippets.

@erikeldridge
erikeldridge / index.html
Created July 18, 2012 05:37
pushState routing boilerplate
<!DOCTYPE html>
<html>
<body>
<a href="/edit/1" class="js-nav">edit</a><br/>
<a href="/1" class="js-nav">1</a><br/>
<a href="/" class="js-nav">default</a><br/>
<a href="#" class="create">create</a>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
var views = {};
@erikeldridge
erikeldridge / debug.sh
Created June 15, 2012 08:01
A collection of web server debug utils
# A collection of web server debug utils
# Described in http://erikeldridge.com/blog/unix
# Inspired by the work of @Pufferfish
apache_access_log=/var/log/apache2/access_log
rails_root=/usr/local/project
rails_prod_log=$rails_root/log/production.log
function tail_apache_access_log() {
tail -f $apache_access_log
@erikeldridge
erikeldridge / app_init.sh
Created April 8, 2012 20:56
Initialize heroku-ready sinatra/mustache app
echo -e "\n$0: Creating project\n"
app_name=`heroku apps:create | ruby -e 'ARGF.read =~ /([\w-]+)\.herokuapp/; puts $1'`
git clone git@heroku.com:$app_name.git
cd $app_name
echo -e "\n$0: Creating .rvmrc\n"
echo "rvm ruby-1.8.7-p330" > .rvmrc
rvm rvmrc load
/**
* @param {number} toothCount is the number of teeth in the barracuda's mouth (required)
* @param {number} weight is the weight of the barracuda
* @param {number} length is the length of the barracuda
*/
function barracuda(toothCount, weight, length){
//...
}
@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: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
@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');
require 'router'
use Rack::CommonLogger
use Rack::ShowExceptions
use Rack::Lint
use Rack::Static, :urls => ["/static"]
run Router.new