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 / mandelbash.rb
Created June 19, 2012 13:39
Explore Mandelbrot set in your terminal using only Ruby core features!
# Built on pseudo-code from http://en.wikipedia.org/wiki/Mandelbrot_set#Computer_drawings
COLORS = %w(1;32 0;32 0;36 1;36 1;37 0;37 1;30 0;30 0;34 1;34 0;35 1;35 0;31 1;31 0;33 1;33)
NUM_COLORS = COLORS.length
# Detect terminal resolution
term_size = `stty size`.split.map { |x| x.to_i }.reverse
X_MAX = term_size[0] - 1
Y_MAX = term_size[1] - 3 # Leave room for help text at bottom
def print_color_block(color)
@sbleon
sbleon / term
Last active May 7, 2019 14:41
Start working on a Rails project
#!/bin/sh
#
# Open a new Mac OS X terminal window or tab in the current or another
# directory and optionally run a command in the new window or tab.
#
# - Without any arguments, the new terminal window opens in
# the current directory, i.e. the executed command is "cd $PWD".
# - If the first argument is a directory, the new terminal will "cd" into
# that directory before executing the remaining arguments as command.
# - The optional "-t" flag executes the command in a new tab
@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 / lussh
Created February 19, 2013 02:29
lussh - script to authorize your SSH key on a server
#!/bin/bash
# make sure to run this with /bin/bash, NOT /bin/sh
echo
echo This script will help you setup ssh public key authentication.
host=dummy