Skip to content

Instantly share code, notes, and snippets.

class Node
attr_accessor :value, :next_node, :previous_node
def initialize(value, next_node, previous_node)
@value = value
@next_node = next_node
@previous_node = previous_node
end
end
class Node
attr_accessor :value, :next_node, :previous_node
def initialize(value, next_node, previous_node)
@value = value
@next_node = next_node
@previous_node = previous_node
end
end
require "net/http"
require "uri"
module Net
class HTTP
alias old_initialize initialize
def initialize(*args)
old_initialize(*args)
@open_timeout = @read_timeout = 1 # 1 second
@gkop
gkop / debug_json.rb
Last active August 29, 2015 13:57
Debug json API response with object in pry
#!/usr/bin/env ruby
# Usage:
# $ curl http://date.jsontest.com | ./debug_json.rb
r = $stdin.dup
input = r.read
$stdin.reopen("/dev/tty")
require 'json'
require 'recursive-open-struct'
require 'awesome_print'
@gkop
gkop / dog.coffee
Created January 29, 2014 04:48
Dog class in coffee
class Dog
age: ->
@human_age * 7.002
my_dog = new Dog()
my_dog.human_age = 4.5
my_dog.name = "Stewie"
my_dog.greeting = ->
"Woof! I'm #{this.name}"
@gkop
gkop / gist:6701598
Last active December 23, 2015 22:09
Blacklist known-incompatible browsers and versions in Rails
# assumes UserAgent gem is available
# https://rubygems.org/gems/useragent
class ApplicationController < ActionController::Base
# blacklist recognized browser with lower versions than those below
Browser = Struct.new(:browser, :version)
BROWSERS = [
Browser.new("Chrome", "3.0"),
Browser.new("Firefox", "3.0"),
@gkop
gkop / tweaks.md
Last active December 17, 2015 17:19
Tweaks to ElasticBeanstalk's default Ruby AMI to install gems locally to application

Tweaks to ElasticBeanstalk's default Ruby AMI to install gems locally to application

in /opt/elasticbeanstalk/hooks/appdeploy/pre/11_asset_compilation.sh

Replace bundle with bundle exec at line 13


in /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh

@gkop
gkop / Gemfile
Last active December 14, 2015 01:49
Bundle from git a gem with additional require paths
source 'https://rubygems.org'
# bundle from git and the ext/ directory in the gem is not found in the require path
gem 'rbtagger', :git => "git://github.com/taf2/rb-brill-tagger.git"
# bundling from rubygems or local path works, however
# gem 'rbtagger'
# or
# gem 'rbtagger', :path => "~/play/rb-brill-tagger"
require 'benchmark'
array = (0..10000000).to_a
benchmark = Benchmark.bm(10) do |x|
x.report("Ruby 2.0: ") do
100000.times { array.bsearch { |e| 7777777 <=> e } }
end
require 'bsearch'
x.report("bsearch gem:") do
@gkop
gkop / notes.md
Created January 9, 2013 05:09
Noisebridge Ruby and Rails class 1/8/13: Rails 4 New Features (notes)