Skip to content

Instantly share code, notes, and snippets.

if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
# RVM is unavailable at this point.
raise "RVM ruby lib is currently unavailable."
@elvuel
elvuel / exit-codes.sh
Created May 18, 2011 07:07 — forked from defunkt/exit-codes.sh
Ruby exit codes
$ ruby -e 'exit'
$ echo $?
0
$ ruby -e 'exit 1'
$ echo $?
1
$ ruby -e 'abort "oh no"'
oh no
$ echo $?
1
@elvuel
elvuel / gist:982304
Created May 20, 2011 03:43 — forked from oisin/gist:952572
API version checking using Sinatra's before filter
require 'sinatra'
# Set the version of the API being run here
#
MAJOR_VERSION = 1
MINOR_VERSION = 0
helpers do
def version_compatible?(nums)
return MAJOR_VERSION == nums[0].to_i && MINOR_VERSION >= nums[1].to_i
@elvuel
elvuel / installation.sh
Created August 28, 2011 11:15 — forked from mikhailov/installation.sh
Nginx+passenger application config: ssl redirection, http headers, passenger optimal settings. see details: http://mikhailov.posterous.com/nginx
$ cd /usr/src
$ wget http://nginx.org/download/nginx-0.8.52.tar.gz
$ tar xzvf ./nginx-0.8.52.tar.gz
$ rm ./nginx-0.8.52.tar.gz
$ gem install s3sync capistrano capistrano-ext passenger --no-ri --no-rdoc
$ passenger-install-nginx-module
# Automatically download and install Nginx? 2. No: I want to customize my Nginx installation
# Where is your Nginx source code located?: /usr/src/nginx-0.8.52
# Where do you want to install Nginx to?: /opt/nginx
@elvuel
elvuel / gist:1244205
Created September 27, 2011 02:58 — forked from fbatista/gist:971221
Oauth2 Flow
+----------+
| |
| User |
| |
+----------+
^
|
(B)
+----+------+ Client Identifier +---------------+
| +----(A)--- & Redirect URI ------>| |
module Rack
class Callbacks < ::Array
DUMMY_APP = proc {|env| }
def initialize(app, &block)
@app = app
instance_eval(&block) if block_given?
end
def use(middleware, *args, &block)
@elvuel
elvuel / gist:1311124
Created October 25, 2011 02:18 — forked from wildjcrt/gist:919198
.profile
[ -f ~/.git-bash-completion.sh ] && . ~/.git-bash-completion.sh
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
[[ -s /Users/jcrt/.rvm/scripts/rvm ]] && source /Users/jcrt/.rvm/scripts/rvm
function git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
echo "("${ref#refs/heads/}") ";
}
@elvuel
elvuel / git_svn_bash_prompt.sh
Created October 27, 2011 02:10 — forked from alexspurling/git_svn_bash_prompt.sh
Update of prompt colours and terminal title
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the branch/status of the current git repository
# * the branch of the current subversion repository
# * the return value of the previous command
#
# USAGE:
@elvuel
elvuel / 0.md
Created October 28, 2011 09:31 — forked from rstacruz/0.md
JST support for Sinatra

JST Support for Sinatra

Usage

class App < Sinatra::Base
  register 'sinatra/jstsupport'
  serve_jst '/jst.js'
end

This serves all JST files found in /views/**/*.jst.* as /jst.js.

@elvuel
elvuel / error_handler.rb
Created November 4, 2011 09:32 — forked from bdotdub/error_handler.rb
Hoptoad notifier for Sinatra
error do
exception = request.env['sinatra.error']
Hoptoad::Notifier.send_error exception, params, request.env if %w(staging production).include?(ENV['RACK_ENV'])
erb :five_hundred
end