This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Net::SSH::Connection::Session | |
def exec3!(command, env=nil) | |
stdout, stderr, exitstatus = "", "", nil | |
open_channel do |channel| | |
if env then | |
env.each do |name, value| | |
channel.env(name, value) | |
end | |
end | |
channel.exec(command) do |ch, success| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use the following commands to create key.pem & cert.pem | |
# openssl genrsa -out key.pem | |
# openssl req -new -x509 -key key.pem -out cert.pem -days 1095 | |
# open your browser and use | |
# https://127.0.0.1:8080/ | |
require 'socket' | |
require 'openssl' | |
require 'cgi' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage | |
# bar = ProgressBar.new | |
# bar.init | |
# 0.step(100, 0.5) { |i| | |
# bar.update(i) | |
# sleep(rand*0.1) | |
# } | |
# bar.finish | |
# | |
# you can update the progress and render independently if you wish. Use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProxyManager | |
class Proxy | |
attr_reader :address | |
attr_accessor :last_used | |
def initialize(address, last_used=nil) | |
@address = address | |
@last_used = last_used | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Numeric; def cap(min,max) return min if self < min; return max if self > max; self; end; end | |
class Wav | |
module Generators | |
end | |
def self.mnot(str) | |
tones = { | |
'C' => 264.0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MethodCop | |
# guard methods that have side effects with a callback that fires before the method is invoked. If the callback returns a "falsey" value, | |
# the method is halted and will not be called. The callback will return nil instead. | |
# if the method does not have side effects or you depend on its return value, you should NOT use this on that method! | |
def guard_method(guarded_method, guard=nil, &callback) | |
# normalize guard | |
guard = method(guard) if guard.is_a?(Symbol) | |
guard = callback if callback | |
raise ArgumentError, "You can only supply either a guard argument or a block" if block && guard |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Module | |
def swap_method(a, b) | |
x = instance_method(a) | |
y = instance_method(b) | |
define_method(b, x) | |
define_method(a, y) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'strscan' | |
require 'bigdecimal' | |
# This is copied and slightly refactored from BareTest::TabularData | |
# | |
# Example | |
# LiteralParser.parse("nil") # => nil | |
# LiteralParser.parse(":foo") # => :foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'hash/dirty' | |
# DirtyHash behaves just like Hash, but keeps track of changes applied to it. | |
# | |
# @example | |
# dh = DirtyHash.with :x => 1 | |
# dh.clean? # => true | |
# dh.update :y => 2, :z => 4 | |
# dh.changed # => {:y => [:added, 2], :z => [:added, nil, 4]} | |
# dh[:z] = 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pp' | |
puts "Seeding for env '#{Rails.env}'" | |
# disable AR logger | |
old_logger = ActiveRecord::Base.logger | |
ActiveRecord::Base.logger = nil unless $VERBOSE | |
env_seed_file = "#{Rails.root}/db/data/seed/#{Rails.env.downcase}/seeds.rb" | |
# first load yaml files that is "base" loading |