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 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
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
# 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
# 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
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
module Enumerable | |
unless method_defined?(:last) then | |
def last(n=nil) | |
reverse_each_method = method(:reverse_each) | |
has_reverse_each = reverse_each_method && reverse_each_method.owner != Enumerable # native reverse_each needed | |
if n then | |
return_value = [] | |
if has_reverse_each then | |
reverse_each { |val| | |
return_value.unshift(val) |
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 Remplate < AbstractController::Base | |
include AbstractController::Rendering | |
include AbstractController::Layouts | |
include AbstractController::Helpers | |
include AbstractController::Translation | |
include AbstractController::AssetPaths | |
include Rails.application.routes.url_helpers | |
self.view_paths = "app/views" # TODO: get it from Rails.application if available |
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 InheritableAttributes | |
def self.extended(klass) | |
klass.instance_variable_set(:@inheritable_attributes, []) | |
end | |
attr_reader :inheritable_attributes | |
def inheritable_attribute(*args) | |
@inheritable_attributes.concat(args) | |
singleton_class.send :attr_accessor, *args unless args.empty? |
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
Moved to https://github.com/apeiros/available |