Skip to content

Instantly share code, notes, and snippets.

View gregoriokusowski's full-sized avatar

Gregório Chalinski Kusowski gregoriokusowski

View GitHub Profile
@gregoriokusowski
gregoriokusowski / non_tenant_finder.rb
Created January 13, 2012 12:00
Checks for all non-tenant models inside an app/models folder. Easy to run via rails console.
tenant_model_class = TenantModel
%x[ls app/models/].split("\n").each do |w|
begin
model = w[0...-3].camelize.constantize
k = model
while k != Object
if k == ActiveRecord::Base
unless model.include? tenant_model_class
puts model
end
@gregoriokusowski
gregoriokusowski / hiring_rails_dev.txt
Created October 14, 2011 18:26
Estamos contratando
[15:10] gregoriokusowski: lunks
[15:10] gregoriokusowski: no git
[15:11] gregoriokusowski: quero commitar tudo numa paulada
[15:11] lunks: git commit -m 'paulada'
[15:13] gregoriokusowski: aí q tá
[15:13] gregoriokusowski: ele não adiciona
[15:13] gregoriokusowski: aí faço git commit -am "paulada"
[15:13] gregoriokusowski: e ele não pega os untracked
[15:13] gregoriokusowski: mas se faço git commit -uam "paulada"
[15:13] gregoriokusowski: n rola
@gregoriokusowski
gregoriokusowski / stupid_multi_tenancy_conversion.rb
Created September 14, 2011 19:40
A stupid script that may be used a single time to migrate an old data-base to one of those new rails multi-tenancy(scoped) apps. It's not pretty. Not even safe, so watchout =P
%x[ls -R app/models/].split("\n").each do |w|
begin
w[0...-3].camelize.constantize.unscoped.each{ |u| u.update_attribute(:company_id, Company.unscoped.first.id) }
rescue
end
end
@gregoriokusowski
gregoriokusowski / chronno_trigger_ftw.rb
Created August 26, 2011 20:20
Avoids the AR default timestamp records.
# how to use(and abuse) it:
# chronno_trigger_ftw! { my_model_instance.update_attributes(:updated_at => my_custom_date) }
def chronno_trigger_ftw!(&block)
Customer.record_timestamps = false
yield
Customer.record_timestamps = true
end
# a threadsafe with ensure block:
@gregoriokusowski
gregoriokusowski / gist:1174216
Created August 26, 2011 19:28
Spork config with sqlite3 test database and selenium specs.
# https://github.com/jnicklas/capybara/issues/450
# hack
ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
def current_connection_id
# Thread.current.object_id
Thread.main.object_id
end
end
# https://github.com/timcharper/spork/wiki/troubleshooting
@gregoriokusowski
gregoriokusowski / spec_helper.rb
Created April 1, 2011 16:28
How to make Spork work with autotest and rspec. Using a sqlite3 in-memory db.
#how to set spork
require 'spork'
Spork.prefork do
#my old spec_helper.rb here ;)
end
Spork.each_run do
load_schema = lambda {
@gregoriokusowski
gregoriokusowski / find_columns_by_type.rb
Created March 11, 2011 10:54
Method that searches an ActiveRecord::Base for it's columns by type.
#clazz must be the ActiveRecord::Base, and type must be a type symbol
def find_columns(clazz, type)
clazz.columns.select do |c|
c.type == type
end.collect do |c|
c.name
end
end
@gregoriokusowski
gregoriokusowski / unzip.rb
Created March 9, 2011 11:34
A simple unzipper :)
#rubygem: rubyzip
require 'zip/zip'
#Ex.: Unzip.from("my_file.zip").to("my_folder")
class Unzip
def initialize(source)
@source = source
end
def self.from(source)
self.new(source)
@gregoriokusowski
gregoriokusowski / download.rb
Created March 9, 2011 11:26
A simple ruby downloader.
require "open-uri"
#Ex.: Download.from("www.blablabla.com/my_download.txt").to("my_downloaded_file.txt")
class Download
def initialize(source)
@source = source
end
def self.from(source)
self.new(source)
end
@gregoriokusowski
gregoriokusowski / ubuntu.sh
Created March 2, 2011 13:45
with comments
#let the computer on, then closing the notebook lid
gconftool-2 --set '/apps/gnome-power-manager/buttons/lid_battery' --type string 'nothing'
gconftool-2 --set '/apps/gnome-power-manager/buttons/lid_ac' --type string 'nothing'