Skip to content

Instantly share code, notes, and snippets.

# in config/application.rb
# ... snip (bunch of requires) ...
module MyApp
class Application < Rails::Application
# ... snip (config)...
# Make sure deface ignores precompiled views in development
initializer "deface.precompile.remove_inject_views", :before => :add_view_paths do |app|
@jphpsf
jphpsf / line_item_decorator.rb
Created November 19, 2012 06:42
Simple Spree adjusment
#
# Decorate Spree::LineItem model to add keg deposits
# and CRV automatically to the order (derived from
# the package format fees) when line items are changed
#
Spree::LineItem.class_eval do
after_save :update_order_package_fees
def update_order_package_fees
@jphpsf
jphpsf / gist:3889392
Created October 14, 2012 18:23
Trigger a command when file changes (bash function)
function loop {
echo -e "\nWaiting for changes..."
while inotifywait -qr -e close_write .
do
clear && $@ && echo -e "\nWaiting for changes..."
done
}
@jphpsf
jphpsf / rebuild.sh
Created August 24, 2012 03:21
Trigger a command when file changes (useful for rebuild)
function rebuild {
while inotifywait -qr -e close_write $2; do clear && $1 $2; done
}
@jphpsf
jphpsf / collect_with_number.rb
Created May 6, 2012 19:12
alternative collect_with_number
def collect_with_number(number, key, &block)
opts = {}
opts[key] = MAX_NUM_RESULTS
statuses = collect_with_max_id do |max_id|
opts[:max_id] = max_id unless max_id.nil?
opts[key] = number unless number >= MAX_NUM_RESULTS
if number > 0
# Instead of this:
# number -= MAX_NUM_RESULTS
statuses = retryable(:tries => 3, :on => Twitter::Error::ServerError, :sleep => 0) do
@jphpsf
jphpsf / application.html.erb
Created July 16, 2011 05:48
Reuse of the Rails Admin layout for the whole application
# app/views/layouts/application.html.erb
<% head_style 'styles' %>
<% head_javascript 'application' %>
<%= render :file => 'layouts/rails_admin/main' %>
@jphpsf
jphpsf / An example of using storeKeyExists
Created April 25, 2011 01:27
storeKeyExists_example.js
// Does it already exists?
if (MyApp.MyModel.storeKeyExists('foobar')) {
// The key exists, so retrieve the record to update it
var record = MyApp.store.find(MyApp.MyModel, 'foobar');
// We only need to update the sources
record.set('something', 'yeah');
} else {
@jphpsf
jphpsf / source_checkboxes.js
Created April 20, 2011 06:49
SproutCore multiple checkboxes view experiment
// ==========================================================================
// Project: SproutSrchr.SourceCheckboxes
// Copyright: ©2011 My Company, Inc.
// ==========================================================================
/*globals SproutSrchr */
/** @class
This is the source picker: it's a view with a row of checkboxes (1 for each source)
@jphpsf
jphpsf / gist:857988
Created March 7, 2011 02:44
Cucumber features organization
features/projects/creating.feature
features/projects/deleting.feature
features/projects/editing.feature
features/projects/viewing.feature
features/tickets/creating.feature
features/tickets/deleting.feature
features/tickets/editing.feature
features/tickets/viewing.feature
features/tickets/notifications.feature
@jphpsf
jphpsf / gist:781489
Created January 16, 2011 02:35
Using rvm this time, with ree
$ rvm use ruby-1.9.2
Using /usr/local/rvm/gems/ruby-1.9.2-p136
$ time cucumber
...
real 0m19.146s
user 0m9.857s