Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View christos's full-sized avatar

Christos Zisopoulos christos

View GitHub Profile
@RISCfuture
RISCfuture / find_in_batches.rb
Created May 1, 2009 23:30
Reimplementation of find_in_batches that fixes bugs and works with composite_primary_keys
module ActiveRecord::Batches
def find_in_batches(options = {})
relation = self
unless arel.orders.blank? && arel.taken.blank?
ActiveRecord::Base.logger.warn("Scoped order and limit are ignored, it's forced to be batch order and batch size")
end
if (finder_options = options.except(:start, :batch_size)).present?
raise "You can't specify an order, it's forced to be #{batch_order}" if options[:order].present?
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@christos
christos / gist:459765
Created July 1, 2010 09:29 — forked from defunkt/gist:132456
Bash snippet to open new shells in most recently visited dir.
# Bash snippet to open new shells in most recently visited dir.
# Useful if you want to open a new terminal tab at the present
# tab's location.
#
# Put this in your .bashrc or whatever.
pathed_cd () {
if [ "$1" == "" ]; then
\cd
else
@tmm1
tmm1 / gist:504342
Created August 2, 2010 08:37
rails3 patch for perftools.rb cpu/object profiling
diff --git a/Gemfile b/Gemfile
index fd90d42..9dd0146 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,4 +1,6 @@
source 'http://rubygems.org'
+gem 'perftools.rb', '>= 0.4.4'
+gem 'rack-perftools_profiler'
gem 'rails', '3.0.0.rc'
@corey
corey / gist:731256
Created December 7, 2010 00:21 — forked from defunkt/gist:206253
# unicorn_rails -c /data/github/current/config/unicorn.rb -E production -D
rails_env = ENV['RAILS_ENV'] || 'production'
# 16 workers and 1 master
worker_processes (rails_env == 'production' ? 16 : 4)
# Load rails+github.git into the master before forking workers
# for super-fast worker spawn times
preload_app true
@christos
christos / cache_with_comment.rb
Created December 30, 2010 12:32
Surround cached fragments with HTML comments (Rails 2.3 initalizer)
module ActionController
module Caching
module Fragments
def read_fragment_with_comment(name, options)
fragment = read_fragment_without_comment(name, options)
fragment && "\n<!-- cache-hit: #{name} -->\n#{fragment}\n<!-- /cache-hit: #{name} -->\n" || nil
end
alias_method_chain :read_fragment, :comment
@sstephenson
sstephenson / gist:771090
Created January 8, 2011 19:41
Automatic *.test host resolution in OS X
$ sudo su -
# mkdir /etc/resolver
# cat > /etc/resolver/test
nameserver 127.0.0.1
port 2155
^D
^D
$ brew install dnsmasq
$ dnsmasq --port=2155 --no-resolv --address=/.test/127.0.0.1
$ ping foo.test
@trevorturk
trevorturk / cache_assets.rake
Created January 13, 2011 17:38
rake deploy and rake cache_assets for heroku
desc "cache assets"
task :cache_assets => :environment do
paths = ['public/javascripts/all.js', 'public/stylesheets/all.css']
puts "-----> caching assets..."
paths.each do |path|
puts "-----> #{path}"
end
module CpuProf
require 'ffi'
extend FFI::Library
ffi_lib FFI::CURRENT_PROCESS
begin
attach_function :start, :ProfilerStart, [:string], :void
attach_function :stop, :ProfilerStop, [], :void
rescue FFI::NotFoundError => e
STDERR.puts "*** Are you sure you preloaded libprofiler?"
@jaimeiniesta
jaimeiniesta / gist:898669
Created April 1, 2011 19:05
tiendas gratis en Madrid
Tienda gratis de La Piluka
Plaza de Corcubión, 16
Metro: B. del Pilar/Peñagrande
Bus: 147, 42, 49, 83, 132
Tienda gratis de La Prospe
c/ Luís Cabrera 19
91 562 70 19
Metro: Prosperidad o Avda. América.