This file contains 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
['mysql2', 'sequel', 'pp'].each(&method(:require)) | |
DB = Sequel.connect('mysql2://root@localhost/tmp') | |
DB.tables.each {|t| DB.drop_table(t) } | |
def t(name, columns, *rows) | |
DB.create_table(name) do | |
columns.each.with_index do |column, ind| | |
type = rows[0][ind].class.to_s | |
send type, column | |
end |
This file contains 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 SSHKit::Backend::Netssh | |
alias_method :command_orig, :command | |
def command(*a) | |
@user = 'test2' # TODO replace with user to sudo to | |
command_orig(*a) | |
ensure | |
@user = nil | |
end | |
end |
This file contains 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 Net | |
class HTTP | |
alias_method '__initialize__', 'initialize' | |
def initialize(*args,&block) | |
__initialize__(*args, &block) | |
ensure | |
@debug_output = $stderr ### if ENV['HTTP_DEBUG'] | |
end | |
end |
This file contains 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
ruby -rwebrick -e'WEBrick::HTTPServer.new(Port: 8000, DocumentRoot: Dir.pwd).start' |
This file contains 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 'json' | |
require 'set' | |
myself = `go list`.strip | |
deps = Set.new | |
`go list ./...`.each_line do |dep| | |
pdeps = JSON.parse(`mgmt go list -json #{dep}`) | |
deps += pdeps['Deps'] | |
deps += pdeps['TestImports'] if pdeps['TestImports'] |
This file contains 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
package main | |
import "fmt" | |
func f() (int, error) { | |
return 42, nil | |
} | |
func main() { | |
x := 3 |
This file contains 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 Class | |
def acts_as(*args) | |
modules_with_options = [] | |
for arg in args | |
if arg.is_a?(Module) | |
modules_with_options << [arg] | |
elsif arg.is_a?(Hash) | |
raise ArgumentError, "Options without module" unless modules_with_options[-1][0].is_a?(Module) | |
modules_with_options[-1][1] = arg | |
end |
This file contains 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
ActiveRecord::Associations::AssociationCollection.class_eval do | |
def sum_with_enumerable_fallback(*args, &block) | |
if args.empty? && block | |
to_a.sum(&block) | |
else | |
sum_without_enumerable_fallback(*args) | |
end | |
end | |
alias_method_chain :sum, :enumerable_fallback |
This file contains 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
var MyClass = function() { | |
var self = this; | |
$.extend(self, { | |
initialize: function(constructor_arg1, constructor_arg2) { | |
self.method(); | |
}, | |
method: function() { | |
} | |
// other methods below... |
This file contains 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
def parse_rails_log_file(file) | |
# Remove all empty lines | |
lines = file.each_line.map(&:strip).reject(&:empty?) | |
# Use +Enumerable#slice_before+ to slice log file into sections for each request | |
lines.slice_before(/Started (GET|POST|PUT|DELETE)/).each_with_object({}) do |request_log, totals| | |
# Only include successfully finished actions in report | |
if duration = request_log.last[/Completed 200 OK in (?<duration>\d+)ms/, :duration] | |
action_name = request_log.first[/Started (GET|POST|PUT|DELETE) "(?<action>.+?)" for/, :action] | |
totals[action_name] ||= 0 |
OlderNewer