View 01_Annotated_Source.md

I've been doing some work lately with JSON documents in PostgreSQL using jsonb columns. You can query these documents using a GIN index in PG, but the syntax can be a little cumbersome

SELECT "events".* FROM "events" WHERE "events"."body" @> '{"shift":{"user_id":2}}'

You have to construct the right side of the query as a JSON string, which is a bit annoying. So I wondered if I could adapt Arel to do the tedious stuff for me.

View application_controller.rb
class ApplicationController < ActionController::Base
before_filter :require_authentication
private
def require_authentication
unless current_certificate.verify(public_key)
head :forbidden
end
end
View location.js
/**
* `window.location` is a BAD api. Doesn't have a prototype, 'too much recursion' error
* if you try to inspect the constructor. Monkey-patching causes random disappearances
* of the monkey-patched function in Chrome, cloning causes 'too much recursion' in FF.
*
* This is what I'm reduced to. ಠ_ಠ
**/
(function () {
function Location () {
View html_truncate.rb
# By Henrik Nyh <http://henrik.nyh.se> 2008-01-30.
# Free to modify and redistribute with credit.
require "rubygems"
require "hpricot"
module TextHelper
# Like the Rails _truncate_ helper but doesn't break HTML tags or entities.
def truncate_html(text, max_length = 30, ellipsis = "...")
View extendEach.js
(function () {
function extendEach () {
var args = Array.prototype.slice.call(arguments),
child = this;
_.each(args, function (proto) {
child = child.extend(proto);
});
View typeIntent.js
/*
* Copyright (c) 2011 Lyconic, LLC.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
View store_ext.js
amplify.store.remove = function ( key ) {
var value = amplify.store( key );
amplify.store( key, null );
return value;
}
View konami.js
(function ($) {
$.fn.konami = function (callback, code) {
code = code || "38,38,40,40,37,39,37,39,66,65,13";
return this.each(function () {
var kkeys = [];
$(this).keydown(function (e) {
kkeys.push(e.keyCode);
if (kkeys.toString().indexOf(code) >= 0) {
$(this).unbind('keydown', arguments.callee);
callback(e);
View get_flash.rb
def get_flash
signed_message = request.cookies['_project_name_session']
if signed_message.present?
secret = ProjectName::Application.config.secret_token
verifier = ActiveSupport::MessageVerifier.new(secret)
session = verifier.verify(signed_message)
@flash = session.delete('flash')
View load_erb.rb
class << YAML
def load_erb(file)
load(
ERB.new(
IO.read(file)
).result
)
end
end