Skip to content

Instantly share code, notes, and snippets.

View burlesona's full-sized avatar

Andrew Burleson burlesona

  • CoSell
  • Austin, TX
View GitHub Profile
@burlesona
burlesona / gist:11407802
Last active August 29, 2015 14:00
ST2 Settings
{
"color_scheme": "Packages/Color Scheme - Default/SpecialsBoard.tmTheme",
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
".DS_Store",
".tags*",
"*.pyc",
"*.pyo",
"*.exe",
@burlesona
burlesona / hash_date.rb
Created January 11, 2015 02:10
Hash <-> Date
class Hash
def to_date
Date.new fetch(:year), fetch(:month), fetch(:day)
end
end
class Date
def to_hash
{year: year, month: month, day: day}
end
@burlesona
burlesona / method_objects.rb
Last active August 29, 2015 14:13
Methods returning symbols is nice
foo = method def foo
def a(num)
3 * num.to_i
end
n = yield if block_given?
a(n || 3)
rescue
"oops!"
end
@burlesona
burlesona / gist:b6d126844a7391a183ac
Created March 24, 2015 14:04
sinatra stack traces are too long
NameError: NameError: uninitialized constant WorkOrdersRouter::WorkOrdersView
/~/app/routers/work_orders_router.rb:11:in `block (2 levels) in <class:WorkOrdersRouter>'
/~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:1610:in `call'
/~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:1610:in `block in compile!'
/~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:974:in `[]'
/~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:974:in `block (3 levels) in route!'
/~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:993:in `route_eval'
/~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/bundler/gems/sinatra-9929353e6c59/lib/sinatra/base.rb:974:in `block (2 levels) in route!'
/~/.rbenv/v
@burlesona
burlesona / photos_controller.rb
Created January 17, 2012 22:35
Photos Controller - 1-17-2012
class PhotosController < ApplicationController
before_filter :authenticate_user!, :except => [:index, :show]
impressionist :actions=>[:show]
respond_to :html, :json
def index
@search = Photo.search(params[:search])
@search.meta_sort ||= 'created_at.desc'
@photos = @search.page(params[:page]).per(20)
respond_with @photos
@burlesona
burlesona / 1.rb
Created November 11, 2012 21:11
Example of user-friendly association of City and Districts to other models in Rails
# 1. Excerpt of Photo and User model
# Photos can belong to Cities and Districts, and users can browse Cities and
# Districts to see the photos in them. When a user uploads a photo I really want
# them to tell me where the photo came from.
# Also, Users can be from a City and District. This is not currently used for very
# much, but gives me a path to add location-enhanced results for other stuff in the
# future.
@burlesona
burlesona / gist:4220986
Created December 6, 2012 00:57
Stubbing local scope methods from outside a module so you can test methods inside a module
require 'minitest_helper'
require 'helpers/application_helper'
describe ApplicationHelper do
before :all do
@helper = Struct.new(:request).new #Create an empty request method so it can be stubbed
@helper.extend(ApplicationHelper)
end
@burlesona
burlesona / gist:5052509
Created February 27, 2013 22:38
Hash#seek. For getting values out of deeply nested hashes.
# Use like so:
# @key_i_need = @event.seek :coordinator, :api_license, :key
class Hash
def seek(*_keys_)
last_level = self
sought_value = nil
_keys_.each_with_index do |_key_, _idx_|
if last_level.is_a?(Hash) && last_level.has_key?(_key_)
if _idx_ + 1 == _keys_.length
@burlesona
burlesona / ruby_methods.rb
Created July 21, 2016 14:33
Ruby Method Fun
# BEFORE RUBY 2.0
def method(argument,hash)
end
method 1, :foo => "bar", :baz => "qux"
method 1, {:foo => "bar", :baz => "qux"} #identical
method(1, {:foo => "bar", :baz => "qux"}) #identical
@burlesona
burlesona / keybase.md
Created September 20, 2016 16:17
Keybase Proof

Keybase proof

I hereby claim:

  • I am burlesona on github.
  • I am burlesona (https://keybase.io/burlesona) on keybase.
  • I have a public key whose fingerprint is 11DB FA34 1EF9 CF16 2955 D274 E038 68E9 30CF 7D68

To claim this, I am signing this object: