This file contains hidden or 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 SugarScopes | |
def like(query) | |
relation = clone | |
query.each do |column, value| | |
relation = relation.where(arel_table[column].matches(value)) | |
end | |
relation | |
end | |
def asc(column = :id) |
This file contains hidden or 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
# simple preforking echo server in Ruby | |
require "socket" | |
# Create a socket, bind it to localhost:2424, and start listening. | |
# Runs once in the parent. All forked children inherit the socket's | |
# file descriptor. | |
acceptor = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) | |
address = Socket.pack_sockaddr_in(4242, "localhost") | |
acceptor.bind(address) | |
acceptor.listen(10) |
This file contains hidden or 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 "socket" | |
socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0) | |
socket.bind(Socket.pack_sockaddr_in(3000, "localhost")) | |
socket.listen(1) | |
loop do | |
connection = socket.accept[0] | |
connection.gets.match /name=(.+) (.+)/ | |
connection.write "#{$2} 200 OK\nContent-Type: text/html\n\nHello #{$1}" | |
connection.close | |
end |
This file contains hidden or 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: brew install highlight | |
second: add to your .zshrc (or .bashrc) | |
function hlr { | |
highlight --syntax ruby -k Menlo -K 20 -s edit-xcode $1 | pbcopy | |
} | |
third: paste the highlighted code to your Keynote talk. |
This file contains hidden or 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 ActiveRecord::Base | |
mattr_accessor :shared_connection | |
@@shared_connection = nil | |
def self.connection | |
@@shared_connection || retrieve_connection | |
end | |
end | |
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection |
This file contains hidden or 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
page.driver.browser.switch_to.alert.accept | |
page.driver.browser.switch_to.alert.dismiss | |
page.driver.browser.switch_to.alert.text | |
http://code.google.com/p/selenium/wiki/RubyBindings#JavaScript_dialogs |
This file contains hidden or 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 TwitterBootstrapFormBuilder < ActionView::Helpers::FormBuilder | |
delegate :capture, :content_tag, :tag, :to => :@template | |
%w[text_field text_area password_field collection_select].each do |method_name| | |
define_method(method_name) do |name, *args| | |
errors = object.errors[name].any? ? " error" : "" | |
error_msg = object.errors[name].any? ? content_tag(:span, object.errors[name].join(","), :class => "help-inline") : "" | |
content_tag :div, :class => "clearfix#{errors}" do | |
field_label(name, *args) + content_tag(:div, :class => "input#{errors}") do |
This file contains hidden or 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
task :synchronize_site_names => :environment do | |
require "csv" | |
first_line_skipped = false | |
CSV.foreach("doc/sgpd_svp.csv") do |line| | |
first_line_skipped = true and next unless first_line_skipped | |
svp_site_id, svp_site_name, oas_site_name = line |
This file contains hidden or 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
namespace :deploy do | |
namespace :assets do | |
task :precompile, :roles => :web, :except => { :no_release => true } do | |
if capture("cd #{latest_release} && #{source.local.log(source.next_revision(current_revision))} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0 | |
run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile" | |
else | |
logger.info "No changes on assets. Skipping pre-compilation." | |
end | |
end | |
end |
This file contains hidden or 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
$(document).ready(function() { | |
Highcharts.setOptions({ | |
colors: ["#259E01", "#058DC7", "#7F8DA9", "#ADD981", "#DAF0FD", "#CD0D74"], | |
chart: { | |
borderWidth: 0, | |
marginTop: 50, | |
plotBackgroundColor: 'rgba(255, 255, 255, .9)', | |
plotShadow: false, | |
plotBorderWidth: 0, | |
marginLeft: 50, |