Skip to content

Instantly share code, notes, and snippets.

View bloudermilk's full-sized avatar

Brendan Loudermilk bloudermilk

View GitHub Profile
@bloudermilk
bloudermilk / benchmark.rb
Created September 9, 2012 00:40
Ruby single quotes vs. double quotes
require "benchmark"
Benchmark.bm(7) do |bench|
bench.report("single") do
1_000_000.times do
'This is a string of substantial length. I doubt you will have many string
literals in your code that are longer than this, but if there are actually
costs to parsing double quoted strings this should exacerbate that.'
end
end
@bloudermilk
bloudermilk / _README.md
Created September 25, 2012 23:38
nginx config for use with Pow

Installation

Install nginx:

$ brew install nginx

Use custom launchctl plist (see homebrew.mxcl.nginx.plist below):

@bloudermilk
bloudermilk / dsl.rb
Created September 27, 2012 20:01
A syntax for tables
module Admin::TicketsHelper
def admin_tickets_table(tickets)
Tabular.build(tickets) do |table|
# If we're simply adding a few columns where the header would be the
# humanized attribute name and the row would contain the attribute `.to_s`
# then we can use the simple `#columns` method.
table.columns :id, :title
# If the column has custom logic for row values, we can use the `#column`
# method to define it
@bloudermilk
bloudermilk / my_model.rb
Created October 19, 2012 20:11
Allow mass-assignment of type attribute in Rails
class MyModel < ActiveRecord::Base
private
# Allow mass-assignment of the type attribute
def self.attributes_protected_by_default
super - %W[ type ]
end
end
@bloudermilk
bloudermilk / text_areas.coffee
Created November 1, 2012 21:12
Github-style text areas
# Enables {command,ctrl}+enter on all textareas
# Author: Nick Giancola (@patbenatar)
$ ->
$("textarea").keydown (e) ->
if (e.ctrlKey or e.metaKey) and e.keyCode is 13
$("textarea").closest("form").submit()
@bloudermilk
bloudermilk / tmux_clipboard
Created November 5, 2012 21:59
A program for syncing the tmux clipboard with OS X's
#!/bin/sh
# Stolen from Joshua Clayton of thoughtbot:
# http://robots.thoughtbot.com/post/19398560514/how-to-copy-and-paste-with-tmux-on-mac-os-x
PATH=/usr/local/bin:$PATH
while true; do
if test -n "`tmux showb 2> /dev/null`"; then
tmux saveb - | pbcopy && tmux deleteb
@bloudermilk
bloudermilk / backbone.registrar.coffee
Last active October 12, 2015 14:48
Easy backbone view module bootloading
Backbone.View.register = (role) ->
$ => new @(el: element).render() for element in $("@" + role)
@bloudermilk
bloudermilk / nested_resource.rb
Created November 15, 2012 21:30
Idea for a nested resource controller helper
# Provides a helper method for controllers who need to query a nested resource.
# Implements per-request in-memory caching for nested resources as well as
# support for controllers that are also accessed without being nested.
module NestedResource
DEFAULT_OPTIONS = {
optional: false,
class_name: nil,
param: nil
}
@bloudermilk
bloudermilk / soa.md
Last active December 9, 2015 20:18
A collection of notes/resources on implementing SOA.

Single sign-on in a service-oriented architecture

The following document outlines a basic design for implementing single sign-on in a service-oriented architecture with many user-facing apps. I have posted it here hoping to get feedback, so don't be afraid to fork and/or comment with your thoughts.

The design relies on two main components in addition to the user-facing servers (apps) and app-facing servers (services):

@bloudermilk
bloudermilk / stack.md
Last active December 10, 2015 01:28
These are the apps I use.