Skip to content

Instantly share code, notes, and snippets.

@jswanner
jswanner / application.rb
Created June 22, 2012 18:01
Basic auth for certain RefineryCMS page.
module MyApplication
class Application < Rails::Application
config.to_prepare do
Refinery::PagesController.class_eval do
before_filter :require_auth, :only => [:show]
def require_auth
if params[:id] == 'secret-page'
authenticate_or_request_with_http_basic('Administration') do |username, password|
username == 'admin' && password == 'password'
end
@jswanner
jswanner / 0-readme.md
Created July 17, 2012 00:34
ruby-1.9.3-p194 cumulative performance patch.

Patched ruby 1.9.3-p194 for 30% faster rails boot

What is this?

This script installs a patched version of ruby 1.9.3-p194 with patches for boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84). It also includes the new backported GC from ruby-trunk.

Huge thanks to funny-falcon for the performance patches.

@jswanner
jswanner / 0-Ruby-1.9.3-p194
Created July 17, 2012 17:58
Compare: gem executable, bundler binstubs, bundle exec gem executable
$ time rspec --help > /dev/null
real 0m0.292s
user 0m0.221s
sys 0m0.064s
$ time ./bin/rspec --help > /dev/null
real 0m1.167s
user 0m1.017s
sys 0m0.137s
@jswanner
jswanner / address.rb
Created July 18, 2012 17:28
Haversine formula with Arel, with possibility of portability.
class Address < ActiveRecord::Base
def self.order_proximity_to(latitude, longitude)
order(Arel::Nodes::Haversine.new(arel_table[:latitude],
arel_table[:longitude],
latitude,
longitude))
end
end
@jswanner
jswanner / Weather.js.diff
Created July 20, 2012 14:57
Prevent OS X dashboard weather widget from moving around.
--- /Library/Widgets/Weather.wdgt/Weather.js 2012-07-20 10:53:24.000000000 -0400
+++ /Library/Widgets/Weather.wdgt/Weather.js 2012-07-20 10:53:40.000000000 -0400
@@ -406,7 +406,7 @@
if (entry != null)
{
iconData.push(entry);
- maxOffset = entry.voffset > maxOffset ? entry.voffset : maxOffset;
+ // maxOffset = entry.voffset > maxOffset ? entry.voffset : maxOffset;
if (entry.hoffset < 0)
@jswanner
jswanner / routes.rb
Last active December 12, 2015 01:38
Rails 3 concern-like, with options.
sociable = ->(options = {}) {
resources :comments, options
resources :categories, options
resources :tags, options
}
resources :messages do sociable.(only: :create) end
resources :posts, &sociable
resources :items, &sociable
require 'textacular/searchable'
class Book
# :title, String
# :author, String
extend Searchable(:title)
end
Book.create :title => "Poignant Guide to Ruby", :author => "_why"
@jswanner
jswanner / gist:5863448
Created June 25, 2013 23:36
Including multiple modules into class
$ irb
irb(main):001:0> module Mod1
irb(main):002:1> def self.included base
irb(main):003:2> puts 'included Mod1'
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> module Mod2
irb(main):007:1> def self.included base
irb(main):008:2> puts 'included Mod2'
@jswanner
jswanner / .tmux.conf
Last active March 24, 2016 19:46
My tmux conf
unbind C-b
set -g prefix C-a
set -g default-terminal "screen-256color"
set -g history-limit 5000
bind C-a send-prefix
# force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf
@jswanner
jswanner / Gemfile.diff
Created October 7, 2011 19:30
Differences between Rails 3.1.0 & Rails 3.1.1 generated apps
diff -U 0 -r rails-3.1.0/Gemfile rails-3.1.1/Gemfile
--- rails-3.1.0/Gemfile 2011-10-07 12:07:06.000000000 -0400
+++ rails-3.1.1/Gemfile 2011-10-07 12:59:13.000000000 -0400
@@ -3 +3 @@
-gem 'rails', '3.1.0'
+gem 'rails', '3.1.1'
@@ -14,3 +14,3 @@
- gem 'sass-rails', " ~> 3.1.0"
- gem 'coffee-rails', "~> 3.1.0"
- gem 'uglifier'