Skip to content

Instantly share code, notes, and snippets.

View additional_monkey_patches.rb
# encoding: utf-8
# code from:
# and also:
# Serialized columns in AR don't support UTF-8 well, so set the encoding on those
class ActiveRecord::Base
def unserialize_attribute_with_utf8(attr_name)
traverse = lambda do |object, block|
if object.kind_of?(Hash)
jeffyip / rails_json_cookie_session_store.rb
Last active Sep 23, 2020
Monkey Patch Ruby on Rails' cookie based session store to use JSON as its serializer instead of Marshal
View rails_json_cookie_session_store.rb
View convert_string_encoding.rb
# Encodes a string from encoding "from" to encoding "to" in
# a way that works for both ruby 1.8 and 1.9
def convert_string_encoding(to, from, str)
if "1.9".respond_to?(:force_encoding)
str = str.dup if str.frozen?
str.encode(to, from, :undef => :replace)
require 'iconv'
Iconv.conv(to, from, str)
jeffyip / case.rb
Created Oct 14, 2012
Ruby 1.9 Upgrade Guide Examples
View case.rb
class Cocktail
attr_accessor :name
def initialize(name)
@name = name
def liquor
when "journalist": "gin"
when "sazerac": "whiskey"
jeffyip / syntax_check.rb
Created Apr 18, 2012
A Script to Check the Syntax of Ruby Files -- Based off of a git precommit hook
View syntax_check.rb
#!/usr/bin/env ruby
require 'open3'
include Open3
skip_erb_files = true
compiler_ruby = `which rbx`.strip
compiler_ruby = `which ruby`.strip if compiler_ruby.length == 0