Skip to content

Instantly share code, notes, and snippets.

View elandesign's full-sized avatar

Paul Smith elandesign

View GitHub Profile
@elandesign
elandesign / can_squeel.rb
Created November 8, 2011 09:11
Monkey patches to make CanCan work with Squeel
# Drop this into config/initializers to get CanCan working with Squeel
if defined?(Squeel)
module Squeel
module Nodes
class Predicate
alias_method :method, :method_name
alias_method :column, :expr
end
end
@elandesign
elandesign / batch_resource.rb
Created November 8, 2011 09:15
Add find_each and find_in_batches functionality to ActiveResource
# Drop this into config/initializers
# The resource being consumed should honour the :page parameter (works great with will_paginate)
module ActiveResource
module Batches
module ClassMethods
def find_each(options = {})
find_in_batches(options) do |batch|
batch.each do |entry|
@elandesign
elandesign / vcard_generator.rb
Created March 28, 2012 15:56
vcard_generator.rb
require 'rubygems'
require 'vpim'
require 'faker'
Faker::Config.locale = 'en-gb'
File.open('contacts.vcf', 'w') do |file|
1000.times do
fakename = [Faker::Name.last_name, Faker::Name.first_name]
card = Vpim::Vcard::Maker.make2 do |vcard|
@elandesign
elandesign / string-benchmark.rb
Created October 11, 2012 16:14
Different ways to build a 100MB string
require 'benchmark'
require 'stringio'
Benchmark.measure do
string = ''
100_000_000.times do
string << '0'
end
end
# => 17.530000 0.040000 17.570000 ( 17.794845)
#!/bin/bash
# XCode Tools
xcode-select --install
# Homebrew
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
# *nix tools
brew install git imagemagick memcached mongodb mysql nmap openssl qt rabbitmq rbenv ruby-build zookeeper bash-completion
@elandesign
elandesign / 0-readme.md
Last active December 27, 2015 00:59 — forked from burke/0-readme.md

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@elandesign
elandesign / mysql.rb
Created October 31, 2013 10:22
brew formula to install MySQL 5.5.29 (updated URL to point to a valid source)
require 'formula'
class Mysql < Formula
homepage 'http://dev.mysql.com/doc/refman/5.5/en/'
url 'http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.29.tar.gz'
version '5.5.29'
sha1 '40e26b193b6ece86ce97896c0c9c524d479e37be'
bottle do
sha1 '3c5b57df466eb538db58654c5f046ddf7bc675e9' => :mountainlion
@elandesign
elandesign / 3-element-benchmark-array-concatenation.rb
Last active December 29, 2015 02:29
Is it quicker to concatenate individual elements, or construct a new array and add that to the existing one?
require 'benchmark'
repeats = 3
iterations = 1_000_000
def check(repeats, &block)
times = []
repeats.times do
times << Benchmark.realtime(&block)
end
# Return the average
@elandesign
elandesign / ofx-generator
Created December 6, 2013 17:32
Generate an OFX file of dummy, sane(ish) transactions. Used to test bank statement uploads for FreeAgent.
#!/usr/bin/env ruby
# == Synopsis
# Generate a dummy OFX bank transactions file
# Depends on nokogiri, faker and pickup gems
# OFX format reverse engineered from my Nationwide bank download. YMMV.
#
# == Usage
# ofx-generator [options] > file.ofx
#
build_package_patch_ruby_railsexpress() {
fetch_git rvm-patchsets git://github.com/skaes/rvm-patchsets.git master
patch -p1 < rvm-patchsets/master/patches/ruby/1.9.3/p484/railsexpress/07-export-a-few-more-symbols-for-ruby-prof.patch
patch -p1 < rvm-patchsets/master/patches/ruby/1.9.3/p484/railsexpress/08-thread-variables.patch
patch -p1 < rvm-patchsets/master/patches/ruby/1.9.3/p484/railsexpress/09-faster-loading.patch
patch -p1 < rvm-patchsets/master/patches/ruby/1.9.3/p484/railsexpress/10-falcon-st-opt.patch
patch -p1 < rvm-patchsets/master/patches/ruby/1.9.3/p484/railsexpress/11-falcon-sparse-array.patch
patch -p1 < rvm-patchsets/master/patches/ruby/1.9.3/p484/railsexpress/12-falcon-array-queue.patch
patch -p1 < rvm-patchsets/master/patches/ruby/1.9.3/p484/railsexpress/14-show-full-backtrace-on-stack-overflow.patch