Skip to content

Instantly share code, notes, and snippets.

#!/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
# 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)
else
require 'iconv'
Iconv.conv(to, from, str)
end
# encoding: utf-8
# code from: http://techtime.getharvest.com/blog/harvest-is-now-on-ruby-1-dot-9-3
# and also: https://gist.github.com/1976864
# 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)
@bf4
bf4 / case.rb
Created June 28, 2013 21:44 — forked from jeffyip/case.rb
class Cocktail
attr_accessor :name
def initialize(name)
@name = name
end
def liquor
case self.name
when "journalist": "gin"
when "sazerac": "whiskey"

Sandi Metz’ rules for developers

  1. Your class can be no longer than a hundred lines of code.
  2. Your methods can be no longer than five lines of code
  3. You can pass no more than four parameters and you can't just make it one big hash.
  4. In your controller, you can only instantiate one object, to do whatever it is that needs to be done.
  5. Your view can only know about one instance variable.
  6. Your Rails view should only send messages to that object i.e., no Demeter violations.[ "thunder dome principal". Translated: one model in, one model out! ]
  7. Rules are meant to be broken if by breaking them you produce better code. [ ...where "better code" is validated by explaining why you want to break the rule to someone else. ]

The @dhh Drinking Game

Take a drink whenever @dhh:

  1. Drops the f-bomb (or says "shit")
  2. Makes fun of Java (or Struts, Hibernate, etc)
  3. Mentions "frameworks should be extractions, not inventions"
  4. Mentions "constraints are liberating"
  5. Defends TurboLinks or the asset pipeline
  6. Mentions Basecamp
@bf4
bf4 / Gemfile
Last active December 26, 2015 06:19 — forked from JEG2/log_bot.rb
source 'https://rubygems.org'
gem 'cinch', '< 1.2'
require 'sinatra/base'
class FakeGitHub < Sinatra::Base
def simulate_error!
@@simulate_error = true
end
def reset!
@@simulate_error = false
end
@bf4
bf4 / steps.md
Created November 24, 2013 01:45 — forked from rwjblue/steps.md

Start with a machine that is directly accessible to both parties via SSH (linode, EC2, prgmr.com, etc), and that you can add users to. DO NOT USE root!!!!

Usage

##From the hosts local machine:

ssh -R1337:localhost:22 host@<shared server's ip address/hostname>