This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TheModel | |
def name | |
@model_name | |
end | |
def initialize(line) | |
@model_name = extract_name(line).to_s.singularize | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'yaml' | |
@sentence = ARGV.shift | |
def find(path, map) | |
map.each do |key, value| | |
if value.is_a? Hash | |
find("#{path}#{key}.", value) | |
else | |
puts "#{path}#{key} - #{value}" if value =~ /#{@sentence}/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#how to set spork | |
require 'spork' | |
Spork.prefork do | |
#my old spec_helper.rb here ;) | |
end | |
Spork.each_run do | |
load_schema = lambda { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 |
OlderNewer