Skip to content

Instantly share code, notes, and snippets.

@dolzenko
dolzenko / irb-tricks.rb
Last active October 13, 2015 03:27
IRB tricks
# Sessions
irb(main):001:0> s = "mystring"
=> "mystring"
irb(main):002:0> irb s
irb#1(mystring):001:0> size
=> 8
> IRB::ReadlineInputMethod::HISTORY.to_a # prints session history
@dolzenko
dolzenko / bid_parser.py
Last active July 21, 2017 14:51
Parse Google BidRequest/BidResponse with Python
import bidding_pb2
rq = bidding_pb2.BidResponse()
f = open('bid_response.bin', "rb")
rq.ParseFromString(f.read())
print(rq)
f.close()
rq = bidding_pb2.BidRequest()
f = open('bid_request.bin', "rb")
-- Primer on representing non-printable characters in Lua code
function assert_equal(a, b)
if a ~= b then
error(a .. ' is not equal to ' .. b)
end
end
-- Escape sequences in string use decimal character codes, i.e.
assert_equal('\97\98\99', 'abc')
@dolzenko
dolzenko / .Xmodmap
Created November 13, 2012 09:51
Apple compact wired keyboard Layout for Ubuntu
! Swap Alt and Cmd keys.
keycode 37 = Control_L
keycode 133 = Alt_L Meta_L
keycode 64 = Super_L
keycode 108 = Super_R
keycode 134 = Alt_L Meta_L
keycode 108 = Control_R Multi_key
clear Shift
clear Lock
clear Control
@dolzenko
dolzenko / tags.rb
Created October 18, 2012 08:20
Generate TAGS for project and Gems (from Bundler's Gemfile)
require 'bundler'
bundler_paths = []
raise unless File.exist?('Gemfile.lock')
lockfile_contents = Bundler.read_file('Gemfile.lock')
lockfile = Bundler::LockfileParser.new(lockfile_contents)
bundler_paths = lockfile.specs.map do |spec|
spec.__materialize__
spec.full_gem_path
@dolzenko
dolzenko / 1.py
Created October 9, 2012 13:27
Parse Google BidRequest
import realtime_bidding_proto_pb2
msg = realtime_bidding_proto_pb2.BidRequest()
f = open('bid_request.bin', "rb")
msg.ParseFromString(f.read())
f.close()
print msg
smart_resource_url # => show || index || parent || root
@dolzenko
dolzenko / factory_girl_debugging.rb
Created January 25, 2012 10:42
Commands to debug Factory Girl from console
require 'factory_girl_rails'
require 'rspec'
require 'rspec-rails'
require 'rspec/mocks/standalone' # => if factories need stubs (for remote services for example)
include FactoryGirl::Syntax::Methods # make FG methods available at top level, so you can do `> create :user`
def reload_factories!
FactoryGirl.instance_variable_set(:@factories, nil) # => clear loaded factories/sequences
# FactoryGirl.instance_variable_set(:@sequences, nil)
@dolzenko
dolzenko / hoptoad_api.rb
Created January 19, 2012 11:01 — forked from croaky/hoptoad_api.rb
Access the Hoptoad (http://hoptoadapp.com) API with Ruby's ActiveResource
class Hoptoad < ActiveResource::Base
self.site = "https://your_account.airbrake.io"
class << self
@@auth_token = 'your_auth_token'
def find(*arguments)
arguments = append_auth_token_to_params(*arguments)
super(*arguments)
end
@dolzenko
dolzenko / 1.rb
Created October 10, 2011 12:58
Rescuing Resque
> Resque.info
> Resque::Failure::Redis.count
> Resque::Failure::Redis.instance_eval { all(count - 1, 1) } # => last 1 failure
> Resque::Failure::Redis.requeue(0)
> Resque::Failure::Redis.clear