Skip to content

Instantly share code, notes, and snippets.

View peteonrails's full-sized avatar

Peter Jackson peteonrails

View GitHub Profile
@peteonrails
peteonrails / gist:9202498
Created February 25, 2014 04:04
A rose by any other name: Classes are just variables
irb(main):001:0> Function = Proc
=> Proc
irb(main):002:0> Function
=> Proc
irb(main):003:0> f = Function.new { puts "I am a function " }
#<Proc:0x007f14ab5d13c8@(irb):11>
irb(main):004:0> f.call
I am a function
=> nil
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
# inspired by http://ariejan.net/2010/08/23/resque-how-to-requeue-failed-jobs
# retry all failed Resque jobs except the ones that have already been retried
# This is, for instance, useful if you have already retried some jobs via the web interface.
Resque::Failure.count.times do |i|
Resque::Failure.requeue(i) unless Resque::Failure.all(i, 1)['retried_at'].present?
end
# retry all :)
Resque::Failure.count.times do |i|
require "threaded_collections"
threadcount = 2
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
tps = ThreadedCollectionProcessor.new(arr)
tps.process(2) { |thread_id, item| puts "Thread #{thread_id} processed item: #{item}" }

[ ] Put signed contact in Dropbox [ ] Create Freshbooks invoice for first 2 weeks [ ] Create Freshbooks recurring invoice to start after week 3 (weekly) [ ] Create Campfire room [ ] Create Github Repo [ ] Create Trello Board (for Product Design Sprints or Rails MVPs, use Trello template) [ ] Create recurring calendar invites for weekly planning, retros, and daily standups [ ] Create project in Team [ ] Share Team project page with client [ ] Schedule thirty minute meeting with client to go over systems

def tally(options = {})
find(:all, options_for_tally(options.merge({:order =>"count DESC" })))
end
@peteonrails
peteonrails / email regex
Created July 11, 2009 17:31
A decent email regex, but it doesn't handle comments and nesting
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
Ping:~ Pete$ cd Documents/workspace/teal
Ping:teal Pete$ git stash
Usage: /usr/local/git/bin/git-stash [ | save | list | show | apply | clear | create ]
Ping:teal Pete$
# Hm. I think "pop" is supposed to show up in there somewhere. Let's check git help:
Ping:teal Pete$ git help stash
GIT-STASH(1) Git Manual GIT-STASH(1)
=== Epic Snow Leopard Upgrayyyyd Guide ===
Son, you’re now living in the land of 64-bit systems.
That means that some of your 32-bit shit is now broken.
Not all is lost.
== Fixing MySQL weirdness
# This template represents what FasterAgile believes to be the best mix
# of components for ab-initio Rails projects. It includes:
# Mocks with factory_girl instead of fixtures; cucumber and shoulda; friendly_ids
# and canonical links for SEO; HAML and SASS; the Clearance engine; basic sass
# and haml starter files; my favorite plugins and initializers; some utility
# methods that I always use.
#
# Run this template like this:
# rails <myproject> -m fasteragile.rb
#