Skip to content

Instantly share code, notes, and snippets.

View bloudermilk's full-sized avatar

Brendan Loudermilk bloudermilk

View GitHub Profile
@bloudermilk
bloudermilk / chronic_attribute.rb
Created February 7, 2013 02:34
Puts Chronic in front of date, time, and datetime attributes to allow for flexile input (anything supported by Chronic)
module ChronicAttribute
extend ActiveSupport::Concern
module ClassMethods
def chronic(*attrs)
attrs.each do |attr|
define_method "#{attr}=" do |value|
if value.is_a? String
with_utc do
self[attr] = Chronic.parse(value)
@bloudermilk
bloudermilk / porvo.md
Last active December 12, 2015 04:18
PORVO: Plain old Ruby view objects (draft)
method PageHeaderHelper
  def page_header(title, subtitle = nil, &contents)
    PageHeader.new(self, title, subtitle, &contents)
  end

  class PageHeader
    attr_reader :context, :title, :subtitle

    def initialize(context, title, subtitle = nil)
class Analyzer
class << self
include ActionView::Helpers::NumberHelper
end
CACHE_NAMESPACE = "analyzer"
CACHE_LIFESPAN = 10.minutes
class_attribute :items_to_analyze
@bloudermilk
bloudermilk / view_object.rb
Created January 10, 2013 04:20
How I use POROs to build maintainable views
module FieldsetWithSubtext
def fieldset_with_subtext(main_text, subtext, options = {}, &block)
View.new(self, main_text, subtext, options, &block)
end
class View
attr_reader :context, :main_text, :subtext, :options, :block
def initialize(context, main_text, subtext, options = {}, &block)
@context = context
@bloudermilk
bloudermilk / total_uber_expenses.js
Last active December 10, 2015 11:58
A simple JavaScript snippet you can use to see how much money you've spent on Uber cars
// Instructions:
// 1. Visit https://clients.uber.com/#!/dashboard
// 2. Click the "Show all trips" link
// 3. Paste the following into the console
// 4. Gasp in horror as you see how much money you've spent on Uber
_($("td.num:contains($)")).map(function (el) { return $(el).text().substring(1) }).map(Number).reduce(function(memo, num) { return memo + num; })
@bloudermilk
bloudermilk / stack.md
Last active December 10, 2015 01:28
These are the apps I use.
@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 / 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 / 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 / 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