Skip to content

Instantly share code, notes, and snippets.

@stim371
stim371 / clear_rails_cache.rb
Created September 6, 2011 00:04
How to clear the query cache in Rails. toss this right before a db call to make sure you're pulling off the db and not the cache. i use this during development, but it should probably be used sparingly in production.
Model.connection.clear_query_cache
@stim371
stim371 / lightbox_mods.js
Created September 6, 2011 00:08
My setup for lightbox, changed the transition speed
//
// Configurationl
//
LightboxOptions = Object.extend({
fileLoadingImage: 'images/loading.gif',
fileBottomNavCloseImage: 'images/closelabel.gif',
overlayOpacity: 0.8, // controls transparency of shadow overlay
animate: true, // toggles resizing animations
@stim371
stim371 / cmd_add_gem
Created September 10, 2011 02:08
setting up static routes in the routes.rb and view files. you need to create an empty controller for Pages where each view gets an empty method.
$ gem install high_voltage
@stim371
stim371 / application_helper.rb
Created September 10, 2011 02:42
app helper to place google analytics
module ApplicationHelper
def google_analytics_js
content_tag(:script, :type => 'text/javascript') do
"var _gaq || [];
_gaq.push(['_setAccount', 'XX-XXXXXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
@stim371
stim371 / alias_these_commands.bash
Created November 6, 2011 00:00
typical git commands
$ git config --global alias.br branch
$ git config --global alias.co checkout
$ git config --global alias.ci commit
$ git config --global alias.pom 'push origin master'
@stim371
stim371 / option expiration callback.rb
Created December 8, 2011 08:11
callback to enter the proper expiration date for the option contract being saved
def calc_exp_date
expirationdate.wday == 6 ? self.expirationdate = expirationdate+(21) : self.expirationdate = expirationdate+(14 + 6 - expirationdate.wday)
end
@stim371
stim371 / js-rubygame-wk3.rb
Created December 28, 2011 06:24
Solutions to therubygame.com week 3 problems
# times are based on 25,000 iterations
# solution 1 / time: 1.47936483s
def capitalize(time)
string.split.each{|n| n.capitalize!}.join ' '
end
# solution 2 / time: 2.32211853s
def capitalize(string)
@stim371
stim371 / gist:1533180
Created December 29, 2011 09:25
list of git cleanup commands
git ls-files --deleted | xargs git rm
ps
lsof -i tcp:3000
kill -int {pid}
@stim371
stim371 / creating_repositories.feature
Created January 24, 2012 09:56
cucumber feature for testing site
Feature: Creating Repositories
In order to have repositories to solicit help on
As a user
I want to add my repositories
Background:
Given I am on the homepage
When I follow "New Repository"
Scenario: Creating a repository
@stim371
stim371 / string_split_benchmark.rb
Created February 11, 2012 10:03
benchmarking different ways of splitting up a string
sentence = "rake routes --help this last part"
def with_split sentence
a = sentence.split('--')
@build_args = "--" << a[1]
@args = a[0]
end
def with_slice sentence
dash_ind = sentence.index("--")