This is a fairly common question, and there isn't a One True Answer.
These are the most common techniques:
require 'rubygems' | |
require 'haml' | |
require 'sinatra' | |
require 'sinatra/flash' | |
require 'file_uploader' | |
enable :sessions | |
get '/' do | |
haml :index |
require 'goliath' | |
class Hello < Goliath::API | |
# default to JSON output, allow Yaml as secondary | |
use Goliath::Rack::Render, ['json', 'yaml'] | |
def response(env) | |
[200, {}, "Hello World"] | |
end | |
end |
# dependencies | |
sudo yum install pkg-config | |
sudo yum install perl-ExtUtils-Embed | |
# Download and extract latest irssi | |
wget http://irssi.org/files/irssi-0.8.15.tar.gz | |
tar tar -xzvf irssi-0.8.15.tar.gz | |
#configure and make | |
cd irssi-0.8.15 |
class Numeric; def cap(min,max) return min if self < min; return max if self > max; self; end; end | |
class Wav | |
module Generators | |
end | |
def self.mnot(str) | |
tones = { | |
'C' => 264.0, |
# coding: utf-8 | |
require 'sinatra' | |
set server: 'thin', connections: [] | |
get '/' do | |
halt erb(:login) unless params[:user] | |
erb :chat, locals: { user: params[:user].gsub(/\W/, '') } | |
end | |
get '/stream', provides: 'text/event-stream' do |
require 'mongo_mapper'
def setup_mongo_connection(mongo_url)
# From bcrypt-ruby gem | |
require 'bcrypt' | |
class User | |
include DataMapper::Resource | |
attr_accessor :password, :password_confirmation | |
property :id, Serial | |
property :username, String, :required => true, :length => (2..32), :unique => true | |
property :password_hash, String, :length => 60 |
via Gregory Brown (@seacreature) on Twitter:
Wrong way to deal with the 1.9.2 removal of . from the loadpath:
require "./foo/bar"
forces you to run code from your project root$LOAD_PATH.unshift(".")
recreates security issue, and pollutesRight way to deal with the 1.9.2 removal of . from the loadpath:
require_relative "foo/bar"
if you don't need Ruby 1.8 compatibilityAs configured in my dotfiles.
start new:
tmux
start new with session name: