Skip to content

Instantly share code, notes, and snippets.

View bjjb's full-sized avatar

JJ Buckley bjjb

View GitHub Profile
@bjjb
bjjb / anagram_couter.rb
Created May 24, 2012 15:15
Anagram Counter!
module AnagramCounter
def count_anagrams
Hash[group_by { |x| x.split('').sort.join }.map { |x, y| [x, y.length] }]
end
end
Array.send(:include, AnagramCounter)
puts ["abb", "bba", "aba", "bba", "abb", "aab", "abc"].count_anagrams.inspect
@bjjb
bjjb / Rakefile
Created May 19, 2012 17:55
Template for a CV
require 'active_support/core_ext/hash/conversions'
require 'rake/clean'
require 'json'
require 'yaml'
require 'maruku'
require 'mustache'
require 'ostruct'
require 'haml'
CLEAN.include(%w|*.html *.xml *.json *.txt|)
@bjjb
bjjb / UserSession.rb
Created April 26, 2012 23:13
Table-less UserSession "model" for Rails 3
# -*- encoding : utf-8 -*-
class UserSession
include ActiveModel::Conversion
include ActiveModel::Validations
extend ActiveModel::Naming
validates_presence_of :email
validates_presence_of :password
@bjjb
bjjb / application_controller_test.rb
Created September 18, 2010 21:37
Testing ApplicationController before_filter logic in Rails3
require 'test_helper'
class DummyController < ApplicationController
def index
render :nothing => true
end
end
MyApp::Application.routes.disable_clear_and_finalize = true
MyApp::Application.routes.clear!
@bjjb
bjjb / authentication.rb
Created September 18, 2010 21:24
Authlogic extensions in a Rails3 app for HTTP token authentication and deprecation removal - put in config/initializers.
module Authlogic
module Session
# Lets you log in using a HTTP token, using the single_access_token.
# Behaves similarly to Params, but with HTTP, so it's nice for APIs.
module HttpToken
def self.included(klass)
klass.class_eval do
extend Config
include InstanceMethods
persist :persist_by_http_token