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
module MysqlQueryResultsFormatter | |
require 'terminal-table/import' | |
def print_results_of_query query | |
result = ActiveRecord::Base.connection.execute(query) | |
return nil if result.nil? | |
results_table = table do |t| | |
results = result.all_hashes | |
t.headings = results.first.keys | |
results.each do |each_row| |
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
{ scopeName = 'todo'; | |
patterns = ( | |
{ name = 'todo.completed'; | |
match = '^\[X+\]'; | |
}, | |
{ name = 'todo.in_progress'; | |
match = '^\[X*\.*\]'; | |
}, | |
{ name = 'todo.new'; | |
match = '^\[.+]'; |
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
######### MIXIN | |
module SplittableArray | |
def split_by_half | |
middle = (self.size.to_f / 2).floor | |
return [self[0..middle], self[middle+1..self.size]] | |
end | |
end | |
some_array = [1, 2, 3, 4, 5] |
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
# First model: tag.rb | |
# note that pomodori is a custom plural for pomodoro | |
class Tag < ActiveRecord::Base | |
has_and_belongs_to_many :pomodori | |
end | |
# Second model: pomodoro.rb | |
# here is how to define a Rails 3 scope through the join table: |
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
ENV["WATCHR"] = "1" | |
system 'clear' | |
def growl(message) | |
growlnotify = `which growlnotify`.chomp | |
title = "Watchr Test Results" | |
puts message | |
image = message.match(/\s0\s(errors|failures)/) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png" | |
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'" | |
system %(#{growlnotify} #{options} &) |
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
module Autotest::Notify | |
def self.notify title, msg, img, pri='low', time=3000 | |
`notify-send -i #{img} -u #{pri} -t #{time} '#{msg}'` | |
end | |
Autotest.add_hook :initialize do |at| | |
%w{.svn .hg .git vendor}.each {|exception| at.add_exception(exception)} | |
end | |
Autotest.add_hook :ran_command do |autotest| |
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 'rubygems' | |
require 'stringex' | |
strings = ["Bolesława", "Poznań", "Stańczyk", "Šaković" ] | |
strings.each do |string| | |
puts "#{string} => #{string.to_ascii}" | |
end | |
# Bolesława => Boleslawa | |
# Poznań => Poznan |
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
ActiveRecord::Base.connection.increment_open_transactions | |
ActiveRecord::Base.connection.begin_db_transaction | |
at_exit do | |
ActiveRecord::Base.connection.rollback_db_transaction | |
ActiveRecord::Base.connection.decrement_open_transactions | |
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
# person.rb | |
validates_presence_of :address | |
# person_factory.rb | |
Factory.define :person do |p| | |
p.name 'John' | |
p.surname 'Doe' | |
p.association :address |
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
AREL (0.5ms) INSERT INTO "addresses" ("country", "planet", "created_at", | |
"updated_at") VALUES ('Italy', 'Earth', '2011-06-18 16:45:00.268423', | |
'2011-06-18 16:45:00.268423') |
OlderNewer