Skip to content

Instantly share code, notes, and snippets.

@lchanmann
lchanmann / app.rb
Created January 28, 2011 02:13
sinatra application with file_uploader
require 'rubygems'
require 'haml'
require 'sinatra'
require 'sinatra/flash'
require 'file_uploader'
enable :sessions
get '/' do
haml :index
@igrigorik
igrigorik / hello.rb
Created February 27, 2011 03:01
goliath hello world example
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
@AndrewVos
AndrewVos / install-irssi-on-ec2.sh
Created September 3, 2011 22:58
Installing IRSSI on ec2
# 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
@apeiros
apeiros / wav.rb
Created November 6, 2011 19:10
Fun with pure tones and WAV (see code after __END__)
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,
@canton7
canton7 / 0main.md
Last active November 7, 2023 08:16
Local versions of tracked config files

How to have local versions of tracked config files in git

This is a fairly common question, and there isn't a One True Answer.

These are the most common techniques:

If you can modify your application

@rkh
rkh / chat.rb
Created December 14, 2011 12:55
Simple Chat Application using the Sinatra Streaming API
# 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
@taktran
taktran / mongomapper_cheatsheet.md
Created January 25, 2012 19:39
Mongomapper cheatsheet

Mongomapper cheatsheet

Mongomapper reference

Set up connection

require 'mongo_mapper'

def setup_mongo_connection(mongo_url)
@canton7
canton7 / Sample DataMapper model.rb
Last active September 10, 2018 03:16
Sinatra Auth in a Box
# 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
@rodreegez
rodreegez / gist:1818506
Created February 13, 2012 17:36
Ruby 1.9.2 Load paths

via Gregory Brown (@seacreature) on Twitter:

Wrong way to deal with the 1.9.2 removal of . from the loadpath:

  1. require "./foo/bar" forces you to run code from your project root
  2. $LOAD_PATH.unshift(".") recreates security issue, and pollutes

Right way to deal with the 1.9.2 removal of . from the loadpath:

  1. require_relative "foo/bar" if you don't need Ruby 1.8 compatibility

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name: