Skip to content

Instantly share code, notes, and snippets.

View RichardJordan's full-sized avatar

Richard Jordan RichardJordan

  • Los Angeles, CA
View GitHub Profile
@RichardJordan
RichardJordan / README
Created March 12, 2012 21:19
Testing Gist From Sublime 2
TODO
Add Readme information.
@RichardJordan
RichardJordan / gist:2048567
Created March 16, 2012 04:59
browserid auth with rails
def signIn #with browserid
ans = 'invalid'
if (params['BIDASSERT'] != nil)
assertion = params['BIDASSERT']
audience = request.host_with_port
http = Net::HTTP.new('browserid.org', 443)
http.use_ssl = true
headers = {
'Content-Type' => 'application/x-www-form-urlencoded',
}
@RichardJordan
RichardJordan / richardjordan.zsh-theme
Created February 5, 2013 22:37
My prompt ZSH-theme
PROMPT=$'%B'
PROMPT+=$'┌─['
PROMPT+=$'%b'
PROMPT+=$'%{\e[0%(?.36.31)m%}'
PROMPT+=$' rvm: $(rvm_prompt_info) '
PROMPT+=$'%{\e[0m%}'
PROMPT+=$'%B'
PROMPT+=$']'
PROMPT+=$'%b'
PROMPT+=$'-'

Build your own private, encrypted, open-source Dropbox-esque sync folder

Prerequisites:

  • One or more clients running a UNIX-like OS. Examples are given for Ubuntu 12.04 LTS, although all software components are available for other platforms as well (e.g. OS X). YMMV
  • A cheap Ubuntu 12.04 VPS with storage. I recommend Backupsy, they offer 250GB storage for $5/month. Ask Google for coupon codes.

Software components used:

  • Unison for file synchronization
  • EncFS for folder encryption
require "spec_helper"
describe ExampleController do
context "GET #index" do
let(:resources) { FactoryGirl.create_list(:resource) }
before do
get :index
end
@RichardJordan
RichardJordan / sample_error_handling.rb
Last active August 29, 2015 13:56
Example: error handling
# from this blog post: http://bugroll.com/how-to-write-good-error-messages.html
# an example of good error handling
begin
update_purchase_captured_at!(purchase, captured_at)
rescue Exception => e
Honeybadger.notify(e)
Rails.logger.error(%Q{\
[#{Time.zone.now}][rake purchases:update_captured_at] Error updating \
class SessionsController < ApplicationController
expose(:login_form) { LoginForm.new }
def create
user = User.find_by_email(params[:email])
if user && user.authenticate(params[:password])
reset_session
if params[:remember_me]
cookies.permanent[:auth_token] = user.auth_token
@RichardJordan
RichardJordan / generate_haiku_name.rb
Last active August 29, 2015 13:56
Create haiku name, heroku-style, for sign-up process
module FormUtilities
module GenerateHaikuName
attr_reader :haiku_name
ADJS = [
"autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark",
"summer", "icy", "delicate", "quiet", "white", "cool", "spring", "winter",
"patient", "twilight", "dawn", "crimson", "wispy", "weathered", "blue",
"billowing", "broken", "cold", "damp", "falling", "frosty", "green",
@RichardJordan
RichardJordan / registrations_controller.rb
Last active August 29, 2015 13:56
Registration of user and account: RegistrationsController
# see https://gist.github.com/RichardJordan/9059633 for explanation
# -----------------------------------------------------------------
# in routes.rb - resources :registrations, only: [:new, :create]
class RegistrationsController < ApplicationController
include FormUtilities::GenerateHaikuName
attr_writer :registrar_source
@RichardJordan
RichardJordan / registration_of_user_and_account.md
Last active August 29, 2015 13:56
Registration of user and account: a series of gists which show a way to handle registration where multiple models need to be created and saved.

Registration of user and account

We often need to register both a user and an account at the same time. A popular approach to this is to load up on active_model callbacks but that is a route to future problems. It also encourages far to much coupling to the framework itself.

This approach uses a hexagonal / ports & adapters approach separating out domain logic from Rails. We are using a fewadvanced techniques here.