Skip to content

Instantly share code, notes, and snippets.

View bloudermilk's full-sized avatar

Brendan Loudermilk bloudermilk

View GitHub Profile
@bloudermilk
bloudermilk / com.bloudermilk.reddit_image_downloader.plist
Created October 11, 2013 23:56
Automate reddit_image_downloader on OS X with launchctl/launchd
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.bloudermilk.reddit_image_downloader</string>
<key>ProgramArguments</key>
<array>
<string>/Users/bloudermilk/.rbenv/versions/1.9.3-p327-perf/bin/ruby</string>
<string>/Users/bloudermilk/.rbenv/versions/1.9.3-p327-perf/bin/reddit_image_downloader</string>
@bloudermilk
bloudermilk / memoized-helper-methods.md
Last active June 20, 2024 23:35
Explaining the rationale behind using memoized helper methods for controller resources

Last year I started playing around with using memoized private helper methods in my controllers instead of the traditional instance variable assigns we see in RoR controllers. Here's an example:

class PostsController < ApplicationController
  helper_method :new_post, :post, :posts
  
  def new; end
  def show; end
  def edit; end
 def index; end
jruby-1.7.10
@bloudermilk
bloudermilk / lolcal_variables.rb
Created February 10, 2014 23:56
Is this anti-pattern bad news?
# I find myself turning code like this
cat = Cat.find(params[:cat_id])
laugh_at(cat)
# Into this
laugh_at(
Cat.find(params[:cat_id])
)
[
{
"repo":{
"id":11757750,
"owner":"facebook",
"name":"huxley",
"url":"https://github.com/facebook/huxley",
"homepage":null,
"language":"Python",
"description":"Watches you browse, takes screenshots, tells you when they change."
def input_get
input = gets.chomp
sum[i] = input.to_i
end
def sum
sum = []
i = 0
puts input_get
@bloudermilk
bloudermilk / yield.rb
Last active August 29, 2015 13:58
Example of yield in ruby
def my_fancy_method
# Call the block with 1
yield 1
# Call the block with "cat"
yield "cat"
# Call the block with nothing (i.e. nil)
yield
end
@bloudermilk
bloudermilk / vancouver-to-sf-tour-pack-list.md
Last active March 21, 2018 21:09
Pack List for my Vancouver to San Francisco Pacific Coast tour

To Do

  • Buy missing items
  • Test pack

Essentials

  • Phone
  • Wallet
  • Keys
@bloudermilk
bloudermilk / gravatar.rb
Created February 26, 2016 23:31
Test whether or not a user has Gravatar
require "net/http"
class GravatarGenerator
URL_FORMAT = "http://www.gravatar.com/avatar/%s"
LAST_MODIFIED_TEST_STRING = "Wed, 11 Jan 1984 08:00:00 GMT"
def self.test(email)
url = URI(URL_FORMAT % generate(email))
Net::HTTP.start(url.host, url.port) do |http|

Keybase proof

I hereby claim:

  • I am bloudermilk on github.
  • I am bloudermilk (https://keybase.io/bloudermilk) on keybase.
  • I have a public key whose fingerprint is B54D E33B 3320 0EA7 A7AA 6852 AB19 6B5D 5009 CE58

To claim this, I am signing this object: