Skip to content

Instantly share code, notes, and snippets.

@wtaysom
wtaysom / methodfinder_what.rb
Created December 19, 2011 10:48
_why's Ruby MethodFinder addition tweaked and revised.
require 'methodfinder'
# _why's MethodFinder addition tweaked and revised.
# <http://redhanded.hobix.com/inspect/stickItInYourIrbrcMethodfinder.html>
class MethodFinder
def self.with_redirected_streams
redirect_streams
yield
ensure
@hoverlover
hoverlover / auto_save_and_open_page.rb
Created February 16, 2012 21:18
Auto save_and_open_page on failure for Capybara
module Capybara
def Capybara.auto_save_and_open_page=(val)
@auto_save_and_open_page = !!val
end
def Capybara.auto_save_and_open_page?
@auto_save_and_open_page ||= false
end
end
@hxgdzyuyi
hxgdzyuyi / backbone-mixin.js
Created September 6, 2012 08:21 — forked from dmitry/backbone-mixin.js
Merge backbone views (mixin pattern)
define('backbone', ['lib-underscore', 'lib-backbone'], function () {
Backbone.mixin = function (view, mixin, custom) {
if (custom) {
if (custom.events && mixin.events) {
mixin = _.clone(mixin)
_.defaults(custom.events, mixin.events)
}
_.extend(mixin, custom)
}
var source = view.prototype || view
@wakiki
wakiki / gist:3312792
Created August 10, 2012 09:12
Rails 3 merging scope with OR
# By Steve Leung
# steve@leungs.me
class ActiveRecord::Relation
# temporarily hack for allowing combining scopes with OR
# doesn't add the join tables so need to use .includes manually
# ie. Jobship.includes(:job).or(Jobship.accepted, Jobship.declined).count
def or(*scopes)
clauses = *scopes.map do |relation|
@fxn
fxn / gist:427dca61ec44adf8253b
Last active July 2, 2019 18:14
gzip assets with Capistrano
# Compresses all .js and .css files under the assets path.
namespace :deploy do
# It is important that we execute this after :normalize_assets because
# ngx_http_gzip_static_module recommends that compressed and uncompressed
# variants have the same mtime. Note that gzip(1) sets the mtime of the
# compressed file after the original one automatically.
after :normalize_assets, :gzip_assets do
on release_roles(fetch(:assets_roles)) do
assets_path = release_path.join('public', fetch(:assets_prefix))
within assets_path do
@ryanb
ryanb / railscasts_episodes.rb
Created June 4, 2012 06:01
Download source code for all RailsCasts episodes. You may want to cd into an empty directory first.
require "rubygems"
require "octokit" # gem install octokit
1.upto(5) do |page|
Octokit.repositories("railscasts", page: page, per_page: 100).each do |repo|
system "git clone git://github.com/railscasts/#{repo.name}"
end
end
@jodosha
jodosha / Gemfile
Last active December 9, 2020 15:09
Full stack Lotus application example
source 'https://rubygems.org'
gem 'rake'
gem 'lotus-router'
gem 'lotus-controller'
gem 'lotus-view'
group :test do
gem 'rspec'
gem 'capybara'
@rainchen
rainchen / gist:6363948
Created August 28, 2013 09:13
Install specific version of Homebrew formula
# Install specific version of Homebrew formula
# usage example:
# $ brew-install ssh-copy-id 6.0p1
function brew-install {
local formula version formula_hash
formula=$1
version=$2
cd `brew --prefix`
git_last_commit_id=`git rev-parse --short HEAD`
@shtirlic
shtirlic / gist:5052306
Last active November 18, 2021 17:58 — forked from joelmoss/gist:2470666
set :stage, 'production'
set :shared_children, shared_children << 'tmp/sockets'
puma_sock = "unix://#{shared_path}/sockets/puma.sock"
puma_control = "unix://#{shared_path}/sockets/pumactl.sock"
puma_state = "#{shared_path}/sockets/puma.state"
puma_log = "#{shared_path}/log/puma-#{stage}.log"
namespace :deploy do
desc "Start the application"
@solnic
solnic / type_safe_entity_vs_ar.rb
Last active November 24, 2021 02:23
Fetching type-safe entity with rom repo vs AR
Calculating -------------------------------------
type-safe users 273.000 i/100ms
ar user models 257.000 i/100ms
-------------------------------------------------
type-safe users 2.813k (± 1.7%) i/s - 14.196k
ar user models 2.574k (±10.7%) i/s - 12.850k
Comparison:
type-safe users: 2812.7 i/s
ar user models: 2574.2 i/s - 1.09x slower