Skip to content

Instantly share code, notes, and snippets.

# Depends on working pdftk, gm (GraphicsMagick), and pdftotext (Poppler) commands.
# Splits a pdf into batches of N pages, creates their thumbnails and icons,
# as specified in the Job options, gets the text for every page, and merges
# it all back into a tar archive for convenient download.
#
# See <tt>examples/process_pdfs_example.rb</tt> for more information.
class ProcessPdfs < CloudCrowd::Action
# Split up a large pdf into single-page pdfs. Batch them into 'batch_size'
# chunks for processing. The double pdftk shuffle fixes the document xrefs.
@heisters
heisters / bdd.vim
Created December 30, 2009 20:08
Run RSpec and Cucumber from vim, on the current spec/feature
" Vim functions to run RSpec and Cucumber on the current file and optionally on
" the spec/scenario under the cursor. Within the context of a Rails app, will
" prefer script/spec and script/cucumber over their system counterparts.
function! RailsScriptIfExists(name)
" Bundle exec
if isdirectory(".bundle") || (exists("b:rails_root") && isdirectory(b:rails_root . "/.bundle"))
return "bundle exec " . a:name
" Script directory
elseif exists("b:rails_root") && filereadable(b:rails_root . "/script/" . a:name)
return b:rails_root . "/script/" . a:name
# Depends on working pdftk, gm (GraphicsMagick), and pdftotext (Poppler) commands.
# Splits a pdf into batches of N pages, creates their thumbnails and icons,
# as specified in the Job options, gets the text for every page, and merges
# it all back into a tar archive for convenient download.
#
# See <tt>examples/process_pdfs_example.rb</tt> for more information.
class ProcessPdfs < CloudCrowd::Action
# Split up a large pdf into single-page pdfs. Batch them into 'batch_size'
# chunks for processing. The double pdftk shuffle fixes the document xrefs.
@mnutt
mnutt / Instrument Anything in Rails 3.md
Created September 6, 2010 06:50
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

Just in case you still think bundle sucks, consider the alternative
This is me getting my blog, a very small Rails 2.3 app with only a few dependencies,
Up and running on my local machine
PAINFUL!
~/dev $ git clone paulbarry.com:paulbarry.git
Cloning into paulbarry...
remote: Counting objects: 1408, done.
remote: Compressing objects: 100% (1071/1071), done.
remote: Total 1408 (delta 274), reused 1285 (delta 207)
@kares
kares / integration_test_session_patch.rb
Created October 26, 2010 09:39
making sessions work in integration tests (broken since Rails 2.3.8)
# session is not preserved between requests in integration tests (since 2.3.8)
# https://rails.lighthouseapp.com/projects/8994/tickets/4941-session-is-not-preserved-between-requests-in-integration-tests
# this monkey-fix deals with the issue and is based on the provided patch from
# the above ticket. require in your test_helper or integration_test_helper ...
require 'action_controller/session/abstract_store'
module ActionController
## conduce - be conducive to; "The use of computers in the classroom lead to better writing"
#
# a model+view component for rails that combines the conductor and presenter
# pattern via a model capable of generating view-centric methods
#
module Conducer
# base class
#
@jacobandresen
jacobandresen / jasmine BDD
Created April 12, 2011 23:06
ExtJS 4 Jasmine BDD
var reviewGrid = Ext.create("ReviewGrid", {renderTo: 'review'});
var productStore = Ext.create("ProductStore", {});
var productForm = Ext.create("ProductForm", {store:productStore, renderTo: 'product', reviewGrid: reviewGrid});
describe("ProductForm", function() {
it("should be able to navigate 1 product forward ", function() {
waitsFor(5000, function () {
return ( productStore.isLoading() == false);
}, "productStore load");
@ajvargo
ajvargo / be_allowed_to_match.rb
Created May 10, 2011 04:41
Custom Matcher for Declarative Authorization authorization specs with RSpec
# in spec/spec_helper.rb, add this to make it work:
# require 'support/be_allowed_to'
# RSpec.configure |config|
# config.include(BeAllowedToMatcher)
# end
#
# allows: some_user.should be_allowed_to(:edit, thing)
# some_user.should be_allowed_to(:edit, :things)
# some_user.should be_allowed_to(:edit, thing, in_this_context)
# along with the should_not variants

Handling Parameters

The controller's job is to work with the request parameters and determine how to activate the domain logic and data to respond to requests. The parameters are key to completing that job.

And, at the same time, parameters are the cause of the most problems in a typical controller. A great action method should be about eight lines of Ruby, but many actions spiral out of control with all kinds of switching based on the input parameters.

params Helper

First, a small point of order: people commonly refer to params as a variable but it isn't -- it is a helper method provided by ActionController which returns a hash containing the request parameters.