Skip to content

Instantly share code, notes, and snippets.

View tinogomes's full-sized avatar
😀

Celestino Gomes tinogomes

😀
View GitHub Profile
def extract_fixtures(dirname)
sql = "SELECT * FROM %s"
skip_tables = ["schema_info"]
ActiveRecord::Base.establish_connection
(ActiveRecord::Base.connection.tables - skip_tables).each do |table_name|
extract_fixture_from table_name, "#{dirname}/#{table_name}.yml"
end
end
def extract_fixture_from(table_name, filename)
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery
private
def require_user
unless @current_user
store_location
flash[:notice] = "You must be logged in to access this page"
redirect_to login_url
@tinogomes
tinogomes / remove_files_from.rb
Last active September 16, 2020 02:25
Remove files from
def p80(text = '')
p text
yield if block_given?
end
def remove_files_from(dir_name, subdir = true)
dir = Dir.new(dir_name)
dir.sort.each do |file_name|
unless file_name =~ /^\./
file = "#{dir_name}/#{file_name}"
@tinogomes
tinogomes / my_power_test_unit_testcase.rb
Created May 3, 2009 00:17
Test::Unit::TestCase with PWD methods
require 'test/unit'
module Test
module Unit
module TestCase
def turn_public_methods(klass)
klass.class_eval do
private_instance_methods.each { |instance_method| public instance_method }
private_methods.each { |method| public_class_method method }
end
@tinogomes
tinogomes / gist:130194
Created June 15, 2009 16:14
Rake with arguments
desc "Say hi. Use USER environment variable as default"
task :hi, :user do |t, args|
args.with_defaults(:user => ENV["USER"])
puts "Hi #{args[:user]}!"
end
@tinogomes
tinogomes / usando git bisect automatizado
Created July 10, 2009 01:38
Usando git bisect para encontrar o erro
celestino@macbook:~/Projects/blog (master)
$ git log --pretty=oneline
0a49fcb771a39b7d3931c63a818de94eed5f10e8 limpando o README
245d8ce9d09c1645583e93e53896b638f664e6a2 ajustes no rake do rcov
be76c6dd3a155079e99195e0335382291653efa1 tarefas do rcov
8d7dc0a7b3832965f5fc021467ee44687df31a8e PostController publico
d34b775d33d0887109cd45848ef73a85fcbf0f9c Post com comentarios e comentarios de um post
3a510b83646bef7f1a9f69f9b7efc74a099589f9 substituindo fixtures por factories
7c1e5231858a8afbd409e3437fca80b88831e206 Movi os CRUDS de Post e Comentarios para admin
1d2ab7b0ceaf7257ff812791e06de72ef55d399a merge with branch "comments" <<== o erro está aqui
require "rubygems"
require "benchmark"
params = {}
puts "with params = {}"
Benchmark.bm(16) do |x|
x.report("with if-inline: ") { 1_000_000.times { params[:page] ? params[:page].to_i : 1 } }
x.report("with max......: ") { 1_000_000.times { [params[:page].to_i, 1].max } }
x.report("with or.......: ") { 1_000_000.times { (params[:page] || 1).to_i } }
x.report("with fetch....: ") { 1_000_000.times { params.fetch(:page, 1).to_i } }
dns - http://freedns.ws
google apps - http://google.com/a
yola, pra criar o site - http://www.yola.com/
logonerds, logos por $50 - http://www.logonerds.com/
wuffo, forms builder - http://wufoo.com/
analytics, pra monitorar - http://www.google.com/analytics/
blog (tumblr)
twitter
adwords
@tinogomes
tinogomes / gist:385573
Created April 30, 2010 18:17
Benchmark: !!(value) or (value == expected)
# Benchmark: !!(value) or (value == expected)
require 'benchmark'
n = 5000000
value = :value
Benchmark.bm do |x|
x.report { p( !!(1 < 0 || 1 > 0) ) }
x.report { p( (1 < 0 || 1 > 0) == true ) }
x.report { p( !!(nil || value) ) }
@tinogomes
tinogomes / start_stop_memcached_script.sh
Created June 21, 2010 17:34
Script sample to start/stop for linux with nohup
#!/bin/bash
#
BASE=/tmp
PID=$BASE/app.pid
LOG=$BASE/app.log
ERROR=$BASE/app-error.log
PORT=11211
LISTEN_IP='0.0.0.0'
MEM_SIZE=4