Skip to content

Instantly share code, notes, and snippets.

@chrisgaunt
chrisgaunt / active_admin_heroku.rb
Created June 30, 2011 12:50 — forked from hoverlover/active_admin_heroku.rb
Rails initializer for using ActiveAdmin with Sass on Heroku
if Rails.env.production?
require 'fileutils'
FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets", "admin"))
template_path = "#{Gem.loaded_specs['activeadmin'].full_gem_path}/lib/active_admin/stylesheets"
old_compile_path = "#{Rails.root}/public/stylesheets/admin"
new_compile_path = "#{Rails.root}/tmp/stylesheets/admin"
Sass::Plugin::remove_template_location template_path, old_compile_path
Sass::Plugin::add_template_location template_path, new_compile_path
@chrisgaunt
chrisgaunt / environment.rb
Created June 30, 2011 23:55
Output SQL in the rails console (Rails 3.0.9)
if "script/rails" == $0
ActiveRecord::Base.logger = Logger.new(STDOUT)
end
@chrisgaunt
chrisgaunt / mixins.less
Created July 6, 2011 13:26
LESS CSS Mixins
.box-shadow(@x: 0, @y: 1px, @blur: 1px, @color: #000) {
box-shadow: @x @y @blur @color;
-moz-box-shadow: @x @y @blur @color;
-webkit-box-shadow: @x @y @blur @color;
}
.inset-box-shadow(@x: 0, @y: 1px, @blur: 1px, @color: #000) {
box-shadow: inset @x @y @blur @color;
-moz-box-shadow: inset @x @y @blur @color;
-webkit-box-shadow: inset @x @y @blur @color;
@chrisgaunt
chrisgaunt / .gemrc
Created July 23, 2011 07:01
~/.gemrc to add "--no-ri --no-rdoc" by default when installing gems
gem: --no-ri --no-rdoc
@chrisgaunt
chrisgaunt / git_changlog
Created July 26, 2011 01:41 — forked from le0pard/git_changlog
Automatic git changelog
#!/usr/bin/env ruby
SPECIAL_TOKEN = 'SpecialTokenForSearch'
WITHOUT_MERGES = "--no-merges"
GIT_COMMIT_LINK="https://github.com/some_projects/commit/:commit"
cmd = `git show-ref --tags`
tags = []
cmd.each do |l|
tag_commit, tag_name = l.chomp.split(" ")
@chrisgaunt
chrisgaunt / grid_bookmarklet.js
Created July 29, 2011 13:59
Bookmarklet to apply grids (requires jQuery on the site)
javascript:(function($){var width=990;var columns=25;var gutter=10;var column_width=(width-(gutter*(columns-1)))/columns;var grid_container=$('<div id="grid-container"></div>');grid_container.css('z-index','999999');grid_container.css('position','absolute');grid_container.css('top',0);grid_container.css('left',0);grid_container.css('width','100%');grid_container.css('height',$(document).height()+'px');var grid=$('<div id="grid"></div>');grid.css('width',width+'px');grid.css('margin','0 auto');var column=$('<div id="column"></div>');column.css('height',$(document).height()+'px');column.css('background-color','rgba(50,150,255,.2)');column.css('width',column_width+'px');column.css('float','left');column.css('margin-left',gutter+'px');grid.append(column.clone().css('clear','left').css('margin',0));for(var i=0;i<(columns-1);i++){column.clone().appendTo(grid);};grid_container.append(grid);$('body').append(grid_container);}(jQuery));
@chrisgaunt
chrisgaunt / routes.rb
Created July 31, 2011 03:55 — forked from pixeltrix/routes.rb
Examples of advanced Rails 3.0 routes
Rails.application.routes.draw do
get '/(:locale)/products/(:category)/(page/:page).:extension',
:to => 'products#index',
:as => :products,
:constraints => {
:locale => /[a-z]{2}/,
:category => /.+?/,
:page => /\d+/
},
@chrisgaunt
chrisgaunt / rails_test_engine_cucumber.markdown
Created August 3, 2011 03:57
Rails 3.1: Test engine with Cucumber & test/dummy app

Run from the root of the engine project:

rails generate cucumber:install --capybara

Edit features/support/env.rb and add to the top:

ENV["RAILS_ENV"] ||= "test"
require File.expand_path("../../../test/dummy/config/environment.rb",  __FILE__)
ENV["RAILS_ROOT"] ||= File.dirname(__FILE__) + "../../../test/dummy"
@chrisgaunt
chrisgaunt / address_spec.rb
Created April 26, 2012 04:21 — forked from moklett/address_spec.rb
Toying around with an RSpec DSL for permutations. My real use case is more complex than this example - the large numbers of inputs and outputs makes it more concise to "demonstrate" correctness and expectations than to "spec" it out with traditional, one
describe Address do
permute "validations" do
cases [
[:address, :address_2, :city, :state, :zip, :country, :valid, :errors_on],
[ nil, nil, nil, nil, nil, nil, false, ['address', 'city', 'state', 'zip', 'country']],
['123 Main St', 'Apt 100', 'Pleasantville', 'NC', '12345', 'US', true, []],
['123 Main St' 'Apt 100', 'Pleasantville' 'NC' '12345' nil, false ['country']]
['123 Main St' 'Apt 100', 'Pleasantville' 'NC' '12345' 'U', false ['country']]
['123 Main St' 'Apt 100', 'Pleasantville' 'NC' '12345' 'USA', false ['country']]
]
@chrisgaunt
chrisgaunt / hashtag_counter.rb
Created May 24, 2012 22:57 — forked from kuntoaji/hashtag_counter.rb
Ruby script to count a twitter hashtag and save the result and last_tweet_id to hashtag_counter_result.txt and last_tweet_id.tx
#!/usr/bin/env ruby
# Twitter Hashtag Counter
#
# Script to count a twitter hashtag and save the result and last_tweet_id to
# hashtag_counter_result.txt and last_tweet_id.txt
#
# Requirements: twitter gem.
# To install twitter gem: [sudo] gem install twitter
require 'rubygems'