Skip to content

Instantly share code, notes, and snippets.

View GBH's full-sized avatar
🦀
🦀🦀🦀🦀🦀🦀🦀🦀🦀

Oleg GBH

🦀
🦀🦀🦀🦀🦀🦀🦀🦀🦀
View GitHub Profile
@GBH
GBH / gist:7270563
Last active December 27, 2015 04:59
class Foo
def bar
baz = 'something'
baz + what_with_context(:something)
end
end
module Wat
def what_with_context(id)
instance_exec(&Huh.some_method)
@GBH
GBH / gist:4027748
Created November 6, 2012 21:35
Hash#dig
class Hash
# Accessing deep hash values. For example, given this hash:
# h = {:a => {:b => :c}}
# h.dig(:a, :b)
# => :c
# h.dig(:x, :y, :z)
# => nil
def dig(*path)
first, tail = path[0], path[1..-1]
node = self[first]
resources :objects do
put :publish, :on => :member
end
before_filter :load_object
def update
@object.update_attributes!(params[:object])
@GBH
GBH / gist:3452023
Last active October 9, 2015 06:17
Textmate snippet for `controllertest`. Scope `source.ruby`
require_relative '../test_helper'
class ${1:Model}sControllerTest < ActionController::TestCase
def setup
@${1/./\l$0/} = ${1/./\l$0/}s(:default)
end
def test_get_index
get :index
@GBH
GBH / gist:3451944
Last active October 9, 2015 06:17
Textmate snippet `controller`. Scope `source.ruby`
class ${1:Model}sController < ApplicationController
before_action :build_${1/./\l$0/}, only: [:new, :create]
before_action :load_${1/./\l$0/}, only: [:show, :edit, :update, :destroy]
def index
@${1/./\l$0/}s = ${1:Model}.page(params[:page])
end
def show
@GBH
GBH / gist:2570212
Created May 1, 2012 18:17
Freshbooks OAUTH Song and Dance
require 'oauth'
require 'oauth/signature/plaintext'
c = OAuth::Consumer.new(
'account_name', 'oath_secret', {
:http_method => :post,
:scheme => :query_string,
:signature_method => 'PLAINTEXT',
:oauth_callback => 'oob',
:site => 'https://testingtesting0123.freshbooks.com',
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'pp'
doc = Nokogiri::HTML(open('http://www.ibao.org/html/find_a_broker/mapfind.asp?tcode=13'))
out = []