Skip to content

Instantly share code, notes, and snippets.

View tjh's full-sized avatar

Tim Harvey tjh

View GitHub Profile
==Summary
These instructions detail the configuration of an MS SQL database connection
(and the associated software required) for Ruby on Rails or ActiveRecord. They
rely heavily on input from a variety of blogs (noted with asterisks).
I tested these during the setup of a dev workstation on a Mac Pro with OS X
and a Preview server running CentOS and Plesk 8.6.0.
It seems that ADO doesn't work (or is a nightmare to get working) on a Linux
@tjh
tjh / bodyid.rb
Created October 14, 2009 13:40 — forked from timnovinger/bodyid.rb
###############################################
# place in /app/helpers/application_helper.rb #
###############################################
def bodytag_id
a = controller.class.to_s.underscore.gsub(/_controller$/, '')
b = controller.action_name.underscore
"#{a}-#{b}".gsub(/_/, '-')
end
@tjh
tjh / .irbrc
Created December 22, 2009 14:10 — forked from unixmonkey/.irbrc
# *****************************************
# .irbrc
#
# Tim Harvey - Literacy5
# http://literacy5.com/
#
# Includes tons of visual sugar, based on the
# work of:
#
# UnixMonkey - http://gist.github.com/254551
#
# Convert all ERB templates to HAML in app/views/
#
# Notes
# -- Will delete the existing erb templates
# -- This is a tweaked version from http://snippets.dzone.com/posts/show/6838
#
# Usage
# -- Save as 'hamlize.rb' in APP_PATh/script/
# -- Run with 'ruby script/hamlize.rb' in your app root
-- Colorize the terminal Git display
git config --global color.interactive always
git config --global color.diff always
git config --global color.status always
git config --global color.branch always
# -----------------------------------------
# Extract DB to YML in Rails
# (Put this in "extract_fixtures.rake" in
# the lib/tasks folder)
# -----------------------------------------
namespace :db do
desc 'Create YAML test fixtures from data in an existing database. Defaults to development database. Set RAILS_ENV to override.'
task :extract_fixtures => :environment do
sql = "SELECT * FROM %s"
# *****************************************
# Bootstrap an app DB, loading up sample
# data and performing any db population
# via Faker tasks (db:populate:all)
#
# Comment out the db:populate line if you
# don't have any population tasks and only
# need to erase/reload the db from
# migrations and sample data
#
- f.fields_for :user_achievements do |child_form|
- if child_form.object.user == @user #This is stupid and dangerous
= blah blah blah
# -----------------------------------------
# Oh My Zsh theme
# -----------------------------------------
# Inspired by "xiong-chiamiov" and "robbyrussell"
# Looks like:
# ┌─[tharvey@macbook] - [~/code/test_project] - [git:master ✗ Changed ✗]
# └─[$]>➜
class Tweet < ActiveRecord::Base
def self.latest_text
if Tweet.first.nil? || Tweet.first.created_at < ENV['CACHE_TIMEOUT'].to_i.minute.ago
begin
httpauth = Twitter::HTTPAuth.new(ENV['TWITTER_USR'], ENV['TWITTER_PWD'])
client = Twitter::Base.new(httpauth)
Tweet.delete_all
client.user_timeline.each do |tweet|