Skip to content

Instantly share code, notes, and snippets.

View bnorton's full-sized avatar

Brian Norton bnorton

View GitHub Profile
@bnorton
bnorton / Gemfile
Created April 30, 2012 15:11
RSpec, Capybara, DatabaseCleaner
source 'http://rubygems.org'
gem 'rails'
gem 'ejs'
gem 'i18n-js', :git => 'git://github.com/fnando/i18n-js.git'
gem 'jquery-rails'
gem 'airbrake'
gem 'thin'
group :assets do
@bnorton
bnorton / Alert.h
Last active January 2, 2016 06:09
UIAlertView subclass for block based handling of simple alert messages. Send in a title and message and specify a block to be called when the alert is dismissed.
//
// Alert.h
//
// Created by Brian Norton on 1/4/14.
// Copyright (c) 2014 Brian Norton. MIT.
//
#import <UIKit/UIKit.h>
@interface Alert : UIAlertView <UIAlertViewDelegate> {
@bnorton
bnorton / mongoid.yml
Last active August 29, 2015 13:55
mongoid 4.0 config
## :write
# -1 : Don't verify writes and raise no network errors
# 0 : Don't verify writes and raise network errors
# 1 : Verify writes on the primary node. (default)
# n : Verify writes on n number of nodes.
#
## :read
# :primary : Will always read from a primary node. (default)
# :primary_preferred : Attempt a primary first, then secondary if none available.
# :secondary : Will always read from a secondary node.
@bnorton
bnorton / open.js
Last active August 29, 2015 14:01
Open in App w/ iframe
var url = 'yourapp://link/305923',
iframe = '<iframe src="'+ url + '" style="display:none;"></iframe>';
$('body').append(iframe);
@bnorton
bnorton / array.rb
Last active August 29, 2015 14:02
Convert an array to a proc that applies its members in sequence to the given item
class Array
def to_proc
->(item) do
self.each do|meth|
item = item.send meth
end
item
end
end
@bnorton
bnorton / created_by_week.rb
Created June 11, 2014 04:31
Aggregate records in memory by
puts records.inspect
# #=> [
# {"id": 1, "created_at": 2014-06-04 06:07:31 -0700},
# {"id": 2, "created_at": 2014-06-07 09:03:11 -0700},
# {"id": 3, "created_at": 2014-06-09 07:47:18 -0700}
# ]
records.each_with_object(Hash.new { 0 }) do |record, hash|
hash[record['created_at'].to_date.beginning_of_week] += 1
end
@bnorton
bnorton / ALAssetsLibrary+CoreExt.h
Last active August 29, 2015 14:02
Some helpful ALAssetsLibrary helpers.
//
// ALAssetsLibrary+CoreExt.h
//
// Created by Brian Norton on 6/14/14.
//
@interface ALAssetsLibrary (CoreExt)
+(ALAssetsLibrary *)library;
@bnorton
bnorton / application.html.erb
Last active August 29, 2015 14:21
Ember.js meet Capybara
<!-- ... -->
<%= javascript_include_tag 'test' if Rails.env.test? %>
<!-- ... -->
@bnorton
bnorton / session.rb
Created August 26, 2015 05:34
Skip the default Rails session (when building an API)
class ApplicationController < ActionController::Base
before_action :skip_session
private
def skip_session
request.session_options[:skip] = true
end
end
@bnorton
bnorton / parse-cookie.coffee
Created February 4, 2016 01:07 — forked from madwork/parse-cookie.coffee
Node cookie parser for Rails 4.1 json encypted cookies