Skip to content

Instantly share code, notes, and snippets.

View coderberry's full-sized avatar

Eric Berry coderberry

View GitHub Profile
@coderberry
coderberry / AuthController.java
Created October 28, 2010 16:13
AuthController.groovy
def pickup = {
// Determine if the captcha is picked correctly
if (params.captchaSelection != session.selectedCaptchaText) {
// They selected the correct Captcha image. Continue with Authentication
} else {
flash.message = "You did not click the correct image below. Please Try Again."
}
@coderberry
coderberry / PagerTagLib.java
Created November 24, 2010 18:27
PagerTagLib.groovy
package com.example
import org.springframework.web.servlet.support.RequestContextUtils as RCU
class PagerTagLib {
/**
* Creates next/previous links to support pagination for the current controller
* This is developed to avoid problems with the PostgreSQL count(*) bug.
* http://sql-info.de/postgresql/postgres-gotchas.html#1_7
@coderberry
coderberry / blogPost1.groovy
Created March 29, 2011 16:58
BlogPost1.groovy
class Lead {
static hasMany = [ submissions: Submission ]
Date dateCreated
// ...
}
class Submission {
static belongsTo = [ lead: Lead ]
static hasMany = [ buyerLogs: BuyerLog ]
Lead lead
@coderberry
coderberry / blogPost2.sql
Created March 29, 2011 17:03
blogPost2.sql
SELECT count(l.id)
FROM lead AS l, submission AS s, buyerLog as bl
WHERE l.id = s.leadId
AND s.id = bl.submissionId
AND bl.leadBuyer = $buyerName
AND l.id != $lead.id
AND l.dateCreated::date > $daysAgo
/**
* Count duplicate submissions within 45 days
* SELECT count(l.id)
* FROM lead AS l, submission AS s, buyerLog as bl
* WHERE l.id = s.leadId
* AND s.id = bl.submissionId
* AND bl.leadBuyer = $buyerName
* AND l.id != $lead.id
* AND l.dateCreated::date > $daysAgo
*/
@coderberry
coderberry / queue.rake
Created August 18, 2011 14:33
queue.rake
require 'queue_manager'
namespace :queue do
desc 'Spawn multiple RabbitMQ consumer workers'
task :workers => :environment do
threads = []
queue_name = ENV['QUEUE']
num_workers = ENV['COUNT'] ||= '1'
@coderberry
coderberry / queue_manager.rb
Created August 18, 2011 14:34
queue_manager.rb
require 'bunny'
class QueueManager
attr_reader :bunny, :bunny_exchange
def initialize(settings)
@bunny = Bunny.new(settings)
@bunny.start
@bunny_exchange = @bunny.exchange('', :durable => false)
@coderberry
coderberry / example.rb
Created August 26, 2011 19:31
example testing
# Add this to your test/test_helper.rb below `require 'test_help'`
require 'minitest/autorun'
# Change any tests you want to use the new syntax and filename
lead_submissions_spec.rb
# Example syntax for SPEC:
require 'test_helper'
describe LeadIntake::Core do
@coderberry
coderberry / Ruby.sublime-settings
Created October 13, 2011 23:01
Ruby.sublime-settings
{
// If translate_tabs_to_spaces is true, use_tab_stops will make tab and
// backspace insert/delete up to the next tabstop
"use_tab_stops": true,
"extensions":["Gemfile", "Gemfile.lock", "Vagrantfile", "Thorfile"]
}
@coderberry
coderberry / shortcuts.txt
Created October 14, 2011 15:57
Sublime Text Shortcuts
Sublime Text 2 Shortcuts
⌘+r View methods or functions in a file.
⌃⇧⌘+f Distraction free editing
⌘⇧+k,b Toggle side panel
⌘⇧+p Command palette
⌘+d Select next occurrence of word
⌘⌃+g Select ALL occurrence of word
⌘⌃+a Auto align
⌘⌥⇧+2 Split screen