Skip to content

Instantly share code, notes, and snippets.

@vangberg
vangberg / README
Created February 22, 2009 01:06
Deploying a Sinatra app to Heroku
# Deploying a Sinatra app to Heroku
## Database
The location of the database Heroku provides can be found in the environment
variable DATABASE_URL. Check the configure-block of toodeloo.rb for an example
on how to use this.
## Server
Heroku is serving your apps with thin, with means you have all your thin goodness available,
such as EventMachine.
# This is a snippet from my ~/.irbrc
# You need to gem install ruby2ruby ParseTree
# This is what you do with it
#
# > class Bar; define_method(:foo) { 'ou hai' }; end
# > puts Bar.to_ruby
# class Bar < Object
# def foo
# "ou hai"
/*
* Mclarens Bar: Redis based Instant Messaging
* Nikhil Marathe - 22/04/2010
* A simple example of an IM client implemented using
* Redis PUB/SUB commands so that all the communication
* is offloaded to Redis, and the node.js code only
* handles command interpretation,presentation and subscribing.
*
* Requires redis-node-client and a recent version of Redis
@vvalgis
vvalgis / Capistrano tasks for starting unicorn.rb
Created May 7, 2010 08:13
Capistrano tasks for starting unicorn
set :rails_env, :production
set :unicorn_binary, "/usr/bin/unicorn"
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do
@pjb3
pjb3 / open_method_def_in_textmate.rb
Created March 9, 2011 22:54
You can find at runtime where a method was defined. This is a little hack to then open that method in textmate
> m = 2.days.method(:ago)
=> #<Method: Fixnum(ActiveSupport::CoreExtensions::Numeric::Time)#ago>
> m.__file__
=> "/Users/paul/.rvm/gems/ree-1.8.7-2011.03@deals/gems/activesupport-2.3.5/lib/active_support/core_ext/numeric/time.rb"
> m.__line__
=> 64
> class Method; def open_in_textmate; `mate -l #{__line__} #{__file__}`; end; end
=> nil
> 2.days.method(:ago).open_in_textmate
=> ""
@esperlu
esperlu / mysql2sqlite.sh
Created April 27, 2011 05:46
MySQL to Sqlite converter
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@addyosmani
addyosmani / codereview.md
Created August 25, 2011 12:11
Lessons from a JavaScript code review

#Lessons From A JavaScript Code Review

I was recently asked to review some code for a new JavaScript application and thought I might share some of the feedback I provided as it includes a mention of JavaScript fundamentals that are always useful to bear in mind. Code reviews are possibly the single biggest thing you can do to improve the overall quality of your solutions and if you're not actively taking advantage of them, you're possibly missing out on bugs you haven't noticed being found or suggestions for improvements that could make your code better.

##Challenges & Solutions

Code reviews go hand-in-hand with maintaining strong coding standards. That said, standards don't usually prevent logical errors or misunderstandings about the quirks of a programming language. Even the most experienced developers can make these kinds of mistakes and code reviews can greatly assist with catching them.

Often the most challenging part of code reviews is actually finding an experienced developer you trust to complete

// start up a few different servers with different referring patterns so we can run some tests
var static = require('node-static');
var http = require('http');
var serverPorts = [
8088
]
function startServer(port) {
var file = new static.Server(__dirname);