Skip to content

Instantly share code, notes, and snippets.

View bloudermilk's full-sized avatar

Brendan Loudermilk bloudermilk

View GitHub Profile
@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 / 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
class Analyzer
class << self
include ActionView::Helpers::NumberHelper
end
CACHE_NAMESPACE = "analyzer"
CACHE_LIFESPAN = 10.minutes
class_attribute :items_to_analyze
@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)
@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 / simple-git-flow.sh
Created March 20, 2013 23:48
A simple git workflow
#
# Starting
#
# Start a new feature branch
git checkout -b my_feature
# Make changes
# Add/Commit

N.B. Things that are starred with * are local variable

  • Ok, first generate a new rails app using this format:
    • rails new app_name
    • rails new amit_test_blog
  • Ok, next sketch out your models.
    • We're going to have two models for this blog: User and Post
    • One users can have many posts and many posts can belong to one users
    • Figure out the fields in each model.
    • Users will have these: field:type
@bloudermilk
bloudermilk / bind_role.js
Created April 10, 2013 22:52
Backbone extension to bind roles to Views
// Automatically instantiates views based on the `role` attribute.
//
// Example:
// AA.Views.Workflow = Backbone.View.extend();
// AA.Views.Workflow.bindRole("workflow");
Backbone.View.bindRole = function (role) {
var view = this;
$(function () {
$("@" + role).each(function () {
@bloudermilk
bloudermilk / database_cleaner.rb
Created July 25, 2013 23:07
Example DatabaseCleaner config for fast tests
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.start
end
@bloudermilk
bloudermilk / yo.md
Last active December 22, 2015 08:18
yo yo yo

Yo yo yo

yo yo yo

hey hey hey

server server server

local local local