- Some utilities:
sudo apt-get install vim tmux git
- Copy/paste from the command line:
sudo apt-get install xclip
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
desc "Launch a Capybara session in a console" | |
task capyconsole: :environment do | |
require "capybara" | |
require "pry" | |
driver = case ENV.fetch('DRIVER', 'phantomjs') | |
when 'phantomjs' | |
require "capybara/poltergeist" | |
Capybara.register_driver :poltergeist_debug do |app| |
# Just wanted to clarify my points at the meetup last night. | |
# | |
# There were two different issues intertwined: | |
# (1) Whether to use extend or "include as extend" | |
# (2) When using "include as extend", what is the simplest way to achieve the goal? | |
# | |
# My personal opinion is that the answer to (1) is "extend", not "include as extend", but that | |
# is just my personal opinion. My answer to (2) is a more empirical question. | |
# Using the "extend" approach. Again, I personally prefer the simplicity of this approach, but |
<form method="get" action="/input"> | |
<input type="text" name="input" /> | |
<input type="submit" value="Submit" /> | |
</form> |
class Uri < ActiveRecord::Base | |
belongs_to :job | |
has_many :scrapes | |
def get_request_object options | |
require 'rubygems' | |
require 'typhoeus' | |
request = Typhoeus::Request.new(self.uri, options) |
%w(dm-core dm-timestamps dm-validations dm-aggregates).each {|lib| gem lib, '=1.1.0'} | |
%w(dm-core dm-timestamps dm-validations dm-aggregates dm-migrations RMagick aws ./config).each { |lib| require lib} | |
include Magick | |
DataMapper.setup(:default, ENV['DATABASE_URL'] || 'mysql://root:fa1556cm@localhost/monsoc') | |
S3 = Aws::S3Interface.new(S3_CONFIG['AWS_ACCESS_KEY'], S3_CONFIG['AWS_SECRET_KEY'], {:multi_thread => true, :protocol => 'http', :port => 80} ) | |
module Commentable | |
def people_who_likes | |
self.likes.collect { |l| "<a href='/user/#{l.user.nickname}'>#{l.user.formatted_name}</a>" } |
ActionController::Integration::Session.class_eval do | |
def generic_url_rewriter | |
env = { | |
'REQUEST_METHOD' => "GET", | |
'QUERY_STRING' => "", | |
"REQUEST_URI" => "/", | |
"HTTP_HOST" => host, | |
"SERVER_PORT" => https? ? "443" : "80", | |
"HTTPS" => https? ? "on" : "off", | |
"rack.input" => "wtf" |
# Used to graph results from autobench | |
# | |
# Usage: ruby autobench_grapher.rb result_from_autobench.tsv | |
# | |
# This will generate three svg & png graphs | |
require "rubygems" | |
require "scruffy" | |
require 'csv' | |
require 'yaml' |
# Warning: Loses any scope it may have been called on! | |
def send_all_in_batches(batch_size, method, *args) | |
transaction do | |
start_id = first(:order => 'id ASC').id | |
end_id = first(:order => 'id DESC').id | |
current_id = start_id | |
while current_id <= end_id | |
if time = args.delete(:time) | |
send_at(time, :send_to_batch, current_id, current_id + batch_size, method, *args) | |
else |