Skip to content

Instantly share code, notes, and snippets.

View nesquena's full-sized avatar

Nathan Esquenazi nesquena

View GitHub Profile
@nesquena
nesquena / basic.sql
Created September 7, 2011 01:56
PostgreSQL Common Utility Queries
/* How to calculate postgreSQL database size in disk ? */
SELECT pg_size_pretty(pg_database_size('thedbname'));
/* Calculate size of a table including or excluding the index */
SELECT pg_size_pretty(pg_total_relation_size('big_table'));
SELECT pg_size_pretty(pg_relation_size('big_table')); /* without index */
/* See indexes on a table with `\d tablename` */
@nesquena
nesquena / mini_shoulda.rb
Created September 3, 2011 13:34
MiniTest + Shoulda Compatibility
# http://metaskills.net/2011/01/25/from-test-unit-shoulda-to-minitest-spec-minishoulda/
# Gives you all the the stuff to make existing shoulda tests work!
class MiniTest::Spec
class << self
alias :setup :before unless defined?(Rails)
alias :teardown :after unless defined?(Rails)
alias :should :it
alias :context :describe
end
alias :assert_no_match :refute_match
@nesquena
nesquena / error.md
Created August 6, 2011 02:56
Issue with Padrino and Travis-CI
@nesquena
nesquena / upgrade.md
Created July 28, 2011 05:43
Upgrade to Lion
@nesquena
nesquena / guide.md
Created July 19, 2011 20:14
Speedup Rails Development

RailsDevBoost

Checkout RailsDevBoost:

# Gemfile
gem 'rails-dev-boost', :git => 'git://github.com/thedarkone/rails-dev-boost.git', :require => 'rails_development_boost', :branch => 'rails-2-3'

rails-test-serving

@nesquena
nesquena / benchmark.rb
Created July 18, 2011 18:42 — forked from ernie/benchmark.rb
A benchmark of some enumerable methods
require 'benchmark'
haystack = (1..1_000_000).to_a
needles = 1.upto(100).map {|n| n * 10_000}
module EachDetector
def self.find(haystack, needle)
haystack.each do |v|
return true if v == needle
end
@nesquena
nesquena / index_users_emails.rb
Created July 14, 2011 00:11
Add concurrent index in Postgres Rails migration
class IndexUsersEmails < ActiveRecord::Migration
def self.up
execute "END"
add_pg_index :users, :email, :lock => false
execute "BEGIN"
end
end
@nesquena
nesquena / index.rb
Created July 11, 2011 18:22
Example of using extends
object @posts
attributes :id, :title, :created_at
child :user do
extends "users/show"
end
require 'benchmark'
require 'active_support/all'
require 'httparty'
HOST = "http://listify-it.herokuapp.com"
def benchy(name, count=5)
result = Benchmark.realtime { count.times { HTTParty.get("#{HOST}/debug/#{name}") } } / count.to_f
"#{(result * 1000).round} ms average"
end