Skip to content

Instantly share code, notes, and snippets.

View sbleon's full-sized avatar

Leon Miller-Out sbleon

View GitHub Profile
require 'active_record'
require 'logger'
require 'pp'
puts "Active Record #{ActiveRecord::VERSION::STRING}"
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => '127.0.0.1',
:user => 'root',
class RefinerySetting < ActiveRecord::Base
FORM_VALUE_TYPES = [
['Multi-line', 'text_area'],
['Checkbox', 'check_box']
]
validates :name, :presence => true
serialize :value # stores into YAML format
@sbleon
sbleon / acceptance_stats.rake
Created April 11, 2012 17:52
Add Turnip acceptance test LOC stats to "rake stats"
# lib/tasks/acceptance_stats.rake
#
# Add acceptance tests to "rake stats" output
if Rake::Task.task_defined? 'spec:statsetup'
Rake::Task['spec:statsetup'].enhance do
require 'rails/code_statistics'
::STATS_DIRECTORIES << %w(Acceptance\ tests spec/acceptance) if File.exist?('spec/acceptance')
::CodeStatistics::TEST_TYPES << 'Acceptance tests' if File.exist?('spec/acceptance')
end
end
@sbleon
sbleon / application.js
Created May 9, 2012 14:20
Javascript/Coffeescript namespace pattern
/*
= require jquery
= require namespace
= require js_functions
= require coffee_functions
*/
@sbleon
sbleon / readme.mdown
Created June 6, 2012 16:54
Upgrade a Heroku shared database to the PostgreSQL 9.1 dev plan

Heroku's Postgres Dev Plan lets you use PostgreSQL 9.1 instead of 8.x, which is what their shared-base offering uses.

Please note that the dev plan is in BETA, and is not recommended for use in production systems.

Also, automatic database backups are not available on the dev plan, so make sure you're backing your data up yourself!

@sbleon
sbleon / house_controller.rb
Created October 3, 2012 17:47
Double-decorating objects
class HouseController < ActionController::Base
def show
@house = HouseDecorator.decorate(House.find(params[:id]))
@windows = WindowBlindsDecorator.decorate(@house.windows)
# @windows would be inadvertently double-decorated
# (though this is prevented by previous fix from
# https://github.com/jcasimir/draper/commit/c945cce6f3147c805b4db73580c198016750ad60)
# My pull request would cause an error to be thrown instead.
end
@sbleon
sbleon / keeping_server_sw_up_to_date.md
Created October 30, 2012 19:04 — forked from jaredbeck/keeping_server_sw_up_to_date.md
Keeping server software up to date

Keeping Server Software Up To Date

Goals (Why do we upgrade things?)

Primary goal: Improve Security

Secondary goal: More consistency across servers

@sbleon
sbleon / Intermittent test failure
Created February 21, 2013 16:58
Intermittent test failure in jquery-lazy-images with Poltergeist
1) basic lazy image loading should load the real image only when the user scrolls to it
Failure/Error: page.source.should have_selector 'img[src*="placekitten"]'
expected following output to contain a <img[src*="placekitten"]/> tag:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Dummy</title>
<link href="/assets/application.css" media="all" rel="stylesheet" type="text/css">
<script src="/assets/application.js" type="text/javascript"></script>
# Place all this at the beginning of your spec_helper.rb to avoid sending
# incorrect coverage data to Code Climate.
require 'codeclimate-test-reporter'
SimpleCov.start 'rails' do
# We always want to run the HTML coverage formatter.
formatters = [ SimpleCov::Formatter::HTMLFormatter ]
# Code Climate records the first coverage data it is sent for any single
# commit, and then ignores future reports. If you're running a single spec,
# this will result in the reporting of erroneously low test coverage.
@sbleon
sbleon / upload_to_cloud_files.rb
Created July 24, 2013 16:17
Upload a large file (> 5GB) to Rackspace Cloud Files
require 'rubygems'
require 'fog'
SEGMENT_LIMIT = 5368709119.0 # 5GB -1
BUFFER_SIZE = 1024 * 1024 # 1MB
CONTAINER = 'my-existing-container'
FILE_DIR = '/path/to/my/big/file'
FILE_NAME = 'huge_tarball.tgz'
RACKSPACE_USERNAME = 'my-rackspace-username'
RACKSPACE_API_KEY = 'my-rackspace-api-key'