Skip to content

Instantly share code, notes, and snippets.

@danopia
danopia / database.yml
Created April 25, 2011 04:19
Default SQLite database.yml
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
@mjohnsullivan
mjohnsullivan / named_struct.rb
Created May 2, 2011 14:25
Ruby Struct utilities: use named parameters to create Struct-based objects and return JSON from Structs
# Struct utilities
# Author:: Matt Sullivan (mailto:matt.j.sullivan@gmail.com)
# Attempt to require Ruby Gems; 1.8.X gem support only
begin
require 'rubygems'
rescue LoadError
# Ruby Gems not installed
end
# Colorizes the output of the standard library logger, depending on the logger level:
# To adjust the colors, look at Logger::Colors::SCHEMA and Logger::Colors::constants
require 'logger'
class Logger
module Colors
VERSION = '1.0.0'
NOTHING = '0;0'
@jraines
jraines / confident-code.md
Created May 17, 2011 19:05
Notes on Avdi Grimm's "Confident Code"

Confident Code

timid code

  • Randomly mixes input gathering, error handling, and business logic
  • imposes cognitive load on the reader

confident code

  • no digressions
@pigoz
pigoz / ruby_sql_to_csv.rb
Created May 31, 2011 13:04
Ruby SQL to CSV exporter
require "rubygems"
begin
require 'sequel'
rescue LoadError
puts "Please run gem install sequel"
exit!
end
DB = Sequel.connect(:adapter => 'mysql2',
:host => '127.0.0.1',
@gertig
gertig / devise_ajax_signup
Created August 17, 2011 19:31
Devise Ajax Signup
#registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
def create
params[:user][:password_confirmation] = params[:user][:password]
super
end
end
<!-- Inside any View --->
<%= form_for(:user, :url => "#", :html => { :id => "ajax_signup"}) do |f| %>
@NARKOZ
NARKOZ / whitespace.rake
Created August 30, 2011 01:31
Whitespaaaaaaaace! WHITESPAAAAAAAACE!
# requires BSD sed
namespace :whitespace do
desc 'Removes trailing whitespace'
task :cleanup do
sh %{for f in `find . -type f | grep -v .git | grep -v ./vendor | grep -v ./tmp | egrep ".(rb|js|haml|html|css|sass)"`;
do sed -i '' 's/ *$//g' "$f";
done}, {:verbose => false}
puts "Task cleanup done"
end
class Hash
def to_html
[
'<ul>',
map { |k, v| ["<li><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></li>"] },
'</ul>'
].join
end
end
@spicycode
spicycode / tmux.conf
Created September 20, 2011 16:43
The best and greatest tmux.conf ever
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000
@jfcalvo
jfcalvo / digest.rb
Created October 3, 2011 09:28
Hash of files an strings with Ruby using MD5 and SHA256
require 'digest'
# Get SHA256 Hash of a file
puts Digest::SHA256.hexdigest File.read "data.dat"
# Get MD5 Hash of a file
puts Digest::MD5.hexdigest File.read "data.dat"
# Get MD5 Hash of a string
puts Digest::SHA256.hexdigest "Hello World"
# Get SHA256 Hash of a string using update