Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / gist:2002935
Created March 8, 2012 19:44
Unique table alias names
terms = ['asdf', 'ghjk']
alias_numbers = (1..terms.length).to_a
tags = Tags.arel_table.alias "tags_#{alias_numbers.shift}"
%script#extras-column-template(type="text/x-jquery-tmpl")
%div.extras(data-bind="foreach: extrasAndExpenses")
%div
/ ko text: text
/ /ko
%a.delete-link X
# OR
%script#extras-column-template(type="text/x-jquery-tmpl")
<!DOCTYPE html>
<html>
<head>
<title>on key press test</title>
<script>
function keyPress(e) {
var keynum, keychar;
if(window.event) { // IE
keynum = e.keyCode;
@jswanner
jswanner / gist:1324770
Created October 29, 2011 17:01
Get full sentence for query
> text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'
> query = 'veniam'
> pos = text =~ /#{query}/
=> 142
> prev_period = text.rindex('.', pos) || -1
=> 123
> next_period = text.index('.', pos) || -1
=> 231
> sentence = text[prev_period+1..next_period]
=> " Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
@jswanner
jswanner / gist:1302999
Created October 21, 2011 02:53
Arel example
# before
def self.front_page
where(:front_page => true).select('*, coalesce(position, 999999999) AS position').order('position ASC')
end
# after
def self.front_page
where(:front_page => true).select([
Arel.sql('*'),
Arel::Nodes::NamedFunction.new('COALESCE', [arel_table[:position], 999999999]).as('position')
@jswanner
jswanner / refineryedge.rb
Created October 20, 2011 03:34
Installing RefineryCMS on Edge
gem 'refinerycms', :git => 'git://github.com/gogogarrett/refinerycms.git', :branch => 'heroku'
run 'bundle install'
generate 'refinery:cms'
rake 'db:migrate'
append_file 'Gemfile' do
" # group :development, :test do
# gem 'refinerycms-testing', '~> 2.0'
# end
@jswanner
jswanner / Gemfile.diff
Created October 7, 2011 19:31
Differences between Rails 3.1.1.rc1 & Rails 3.1.1 generated apps
diff -U 0 -r rails-3.1.1.rc1/Gemfile rails-3.1.1/Gemfile
--- rails-3.1.1.rc1/Gemfile 2011-10-07 12:08:28.000000000 -0400
+++ rails-3.1.1/Gemfile 2011-10-07 12:59:13.000000000 -0400
@@ -3 +3 @@
-gem 'rails', '3.1.1.rc1'
+gem 'rails', '3.1.1'
@@ -14,2 +14,2 @@
- gem 'sass-rails', " ~> 3.1.0"
- gem 'coffee-rails', "~> 3.1.0"
+ gem 'sass-rails', '~> 3.1.4'
@jswanner
jswanner / Gemfile.diff
Created October 7, 2011 19:29
Differences between Rails 3.1.0.rc8 & Rails 3.1.1 generated apps
diff -U 0 -r rails-3.1.0.rc8/Gemfile rails-3.1.1/Gemfile
--- rails-3.1.0.rc8/Gemfile 2011-10-07 12:05:37.000000000 -0400
+++ rails-3.1.1/Gemfile 2011-10-07 12:59:13.000000000 -0400
@@ -3 +3 @@
-gem 'rails', '3.1.0.rc8'
+gem 'rails', '3.1.1'
@@ -14,3 +14,3 @@
- gem 'sass-rails', " ~> 3.1.0.rc"
- gem 'coffee-rails', "~> 3.1.0.rc"
- gem 'uglifier'