Skip to content

Instantly share code, notes, and snippets.

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

Oleg GBH

🦀
🦀🦀🦀🦀🦀🦀🦀🦀🦀
View GitHub Profile
#!/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 = []
@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',
@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: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
resources :objects do
put :publish, :on => :member
end
before_filter :load_object
def update
@object.update_attributes!(params[:object])
@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]
@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:9218575
Created February 25, 2014 21:47
Hash#deep_slice
class Hash
def deep_slice(*allowed_keys)
sliced = { }
allowed_keys.each do |allowed_key|
if allowed_key.is_a?(Hash)
key = allowed_key.keys.first
sliced[key] = self[key].deep_slice(*[allowed_key.values].flatten) if self[key]
else
sliced[allowed_key] = self[allowed_key] if self[allowed_key]
@GBH
GBH / gist:a0c6e7ec555881242f61
Created November 17, 2014 14:20
Ruby ancestor chain fun
module Foo
def hello
puts 'foo'
end
end
module Bar
def hello
puts 'bar'
end
vagrant@jun-group:~/player$ rails s torquebox
=> Booting TorqueBox
=> Rails 3.2.18 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
NameError: missing class or uppercase package name (`com.jungroup.player.geocoding.ZipcodeTranslator')
get_proxy_or_package_under_package at org/jruby/javasupport/JavaUtilities.java:54
method_missing at file:/home/vagrant/.rvm/rubies/jruby-1.7.8/lib/jruby.jar!/jruby/java/java_package_module_template.rb:14
(root) at /home/vagrant/player/lib/geo_code.rb:7