Skip to content

Instantly share code, notes, and snippets.

View terrcin's full-sized avatar

terrcin terrcin

View GitHub Profile

Keybase proof

I hereby claim:

  • I am terrcin on github.
  • I am terrcin (https://keybase.io/terrcin) on keybase.
  • I have a public key whose fingerprint is 07A6 FAE1 5DE2 905A 507B 7159 F054 3CBD D1E0 4937

To claim this, I am signing this object:

@terrcin
terrcin / gist:0745f2c6240aad291077
Last active August 29, 2015 14:17
Granting readonly access to rails production console by default
# In our config/deploy.rb we have the below for an easy prod console.
# There are various ways of doing it.
desc "Remote console"
task :console, roles: :app do
server = find_servers(roles: [:app]).first
run_with_tty server, %W( ./script/rails console #{rails_env} )
end
# Turns out there is a '--sandbox' option for the console that will roll back any changes on exit
# allows the 'sc' commands to work for both Rails 2.x and Rails 3
# not mine, found it somewhere online but can't remember where
function sc {
if [ -e script/rails ]; then
script/rails console $@
else
script/console $@
fi
}
module ActiveRecord
module Associations
class HasManyThroughAssociation < HasManyAssociation
protected
# added support for STI with polymorphism
def construct_conditions
table_name = @reflection.through_reflection.quoted_table_name
conditions = construct_quoted_owner_attributes(@reflection.through_reflection).map do |attr, value|
if attr =~ /_type$/
construct_polymorphic_sql(table_name, attr)
@terrcin
terrcin / gist:889801
Created March 28, 2011 00:20
How I open projects in textmate
#!/bin/bash
############################################################################
# Script to open a directory in TextMate excluding certain directories that
# tend to slow down the Find in Project... function.
#
# Place in an executable loctation with a name of your choosing.
# I use `ate' and have it in ~/Local/bin (which has been added to $PATH)
#
# NTW: from here: https://gist.github.com/111999
@terrcin
terrcin / setup-statsd.sh
Created June 10, 2011 10:14 — forked from collegeman/setup-statsd.sh
Turn an Ubuntu 10.04 linode into a StatsD/Graphite server
# install git
sudo apt-get install g++ curl libssl-dev apache2-utils libapache2-mod-wsgi
sudo apt-get install git-core
# download the Node source, compile and install it
git clone https://github.com/joyent/node.git
cd node
./configure
make
sudo make install
# install the Node package manager for later use
begin
token = generate_random_token
end while User.find_by_token(token).nil?
@terrcin
terrcin / gist:2598654
Created May 5, 2012 00:11
Making Temfile.make_tmpname give a better quality unique name
require 'tempfile'
class Tempfile
# overriding so that the Time component of the tmpname including hours, seconds and usecs, was previously just year + month + day
def make_tmpname(basename, n)
case basename
when Array
prefix, suffix = *basename
else
@terrcin
terrcin / vcr_tests.rb
Created July 4, 2012 00:21
Make including VCR in tests real easy
# using the VCR gem:
# https://github.com/myronmarston/vcr/
#
# this wraps each test in a unique VCR cassette and separately the setup method.
#
# require 'vcr_tests' in test_helper.rb
# then in a test file include the VcrTests module after the setup method
module VcrTests
{
"auto_complete": false,
"color_scheme": "Packages/Color Scheme - Default/Slush & Poppies.tmTheme",
"folder_exclude_patterns":
[
".git",
"tmp",
"log"
],
"font_face": "DroidSansMono",