Skip to content

Instantly share code, notes, and snippets.

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
['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
@dolzenko
dolzenko / irb_benchmark.rb
Created January 8, 2014 14:34
Automatic benchmarking in IRB (based on irb_callbacks gem code)
require 'benchmark'
module IRB
def self.before_eval
end
def self.after_eval
end
def self.around_eval(&block)
@timing = Benchmark.measure do
block.call
end
@dolzenko
dolzenko / README.txt
Created January 8, 2014 14:21
irb_callbacks
= irb_callbacks
* http://rubysideshow.rubyforge.org/irb_callbacks
== DESCRIPTION:
This gem adds callbacks to irb, intended for you to
override at your discretion.
== FEATURES:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="780" height="420">
<param name="movie" value="https://impdesk-cdn.s3.amazonaws.com/c5/63/01fa951290d8ccab15bae443cfcc.swf?1385464753" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="https://impdesk-cdn.s3.amazonaws.com/c5/63/01fa951290d8ccab15bae443cfcc.swf?1385464753" width="780" height="420">
<!--<![endif]-->
<a target="_blank" href="http://example.com">
<img
width="607"
height="367"
border="0"
@dolzenko
dolzenko / ack-gems
Created September 5, 2013 15:31 — forked from AndrewRadev/ack-gems
#! /usr/bin/env ruby
require 'bundler'
paths = Bundler.load.specs.map(&:full_gem_path)
system("ack '#{ARGV[0]}' #{paths.join(' ')}")
local pid = io.open('/proc/self/stat'):read('*all'):gmatch('%d+')()
print(io.popen('ps -p ' .. pid .. ' -o cmd,vsz,rss'):read('*all'))
module I18n
class JustRaiseExceptionHandler < ExceptionHandler
def call(exception, locale, key, options)
if exception.is_a?(MissingTranslation)
raise exception.to_exception
else
super
end
end
end
# Not needs as there is 'Copy as Curl' in Chrome now
sqlite3 -separator ' ' ~/.config/google-chrome/Default/Cookies 'select host_key, "TRUE", path, "FALSE", expires_utc, name, value from cookies'
@dolzenko
dolzenko / gotcha.rb
Last active December 18, 2015 18:09
small ruby gotha - BigDecimals divide by 0
irb(main):009:0> 1/BigDecimal.new('0')
=> #<BigDecimal:b36d598,'Infinity',9(36)>
irb(main):010:0> 1/0
ZeroDivisionError: divided by 0