Skip to content

Instantly share code, notes, and snippets.

View cblunt's full-sized avatar
👨‍💻
Coding

Chris Blunt cblunt

👨‍💻
Coding
View GitHub Profile
@cblunt
cblunt / application_helper_spec.rb
Created November 27, 2011 15:36
Testing content_for Helper Methods with RSpec
# Solution from http://www.jamiepenney.co.nz/2011/09/23/testing-content_for-in-rails-3-x-helpers-with-rspec/
describe ApplicationHelper do
describe "title" do
it "should return an h2 tag with the given title" do
helper.title("Lorem Ipsum")
helper.content_for(:page_title).should eql "<h2>Lorem Ipsum</h2>"
end
it "should return the supplied block if a block was given" do
@cblunt
cblunt / Gemfile
Created October 21, 2011 08:55
Configure Carrierwave for Amazon S3 Storage and Heroku
# ...
gem 'carrierwave'
gem 'fog', '~> 1.0.0' # Need to specify version, as carrierwave references older (0.9.0) which doesn't allow configuration of Rackspace UK Auth URL
@cblunt
cblunt / rails_app_template.rb
Last active July 18, 2016 04:21
Rails 4 App Template
# Creates a new Rails 4 application configured with
# Slim, PostgreSQL, TestUnit (minitest), FactoryGirl, SimpleCov, Capybara, Capistrano ...
#
# Based on template generated at http://railswizard.org/
# USAGE
# $ rails new APP_NAME -JTm rails_app_template.rb
# Will be specified by default Gemfile
# gem 'rails', '4.2.0'
@cblunt
cblunt / adb-list-packages.sh
Created June 21, 2011 13:14
List packages installed on an Android device
adb shell pm list packages
@cblunt
cblunt / git_basics.md
Last active March 11, 2024 16:00
A simple git cheatsheet for reference.

Quick Summary

cd my_project

git init .
git add . # add everything
git commit -m 'Initial commit'

... make some changes ...

@cblunt
cblunt / factories.rb
Created October 15, 2010 14:01 — forked from technicalpickles/factories.rb
Simulate paperclip attachments with FactoryGirl in Rails 3
Factory.define :application do |factory|
factory.attachment :sample, "public/samples/sample.doc", "application/msword"
end
@cblunt
cblunt / form_tag_id_helper.rb
Created February 6, 2010 09:28
Small helper to get the generated id of form tags in a Rails fields_for block (http://chrisblunt.com/blog/2009/10/12/rails-getting-the-id-of-form-fields-inside-a-fields_for-block/)
# app/helpers/application_helper.rb
def sanitized_object_name(object_name)
object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")
end
def sanitized_method_name(method_name)
method_name.sub(/\?$/, "")
end
def form_tag_id(object_name, method_name)
@cblunt
cblunt / string_extensions.js
Created July 22, 2009 09:28
Adds an attributize() method to javascript String objects. Converts the sender string into an object attribute format for submission to a server.
Object.extend(String.prototype, {
/**
* Converts an underscore string into object attribute format for submission
* to a server (Based on Rails).
*
* To attributize the string client_firstName
* "client_firstName".attributize()
* => client[first_name]
*
* To attributize the string client_addresses__street