Skip to content

Instantly share code, notes, and snippets.

View tiegz's full-sized avatar
👋
Working from home

Tieg Zaharia tiegz

👋
Working from home
View GitHub Profile
@tiegz
tiegz / advent_of_code_2016.md
Last active December 27, 2016 17:37
Advent of Code 2016
@tiegz
tiegz / keybase.md
Created November 6, 2015 22:41
keybase.md

Keybase proof

I hereby claim:

  • I am tiegz on github.
  • I am tiegz (https://keybase.io/tiegz) on keybase.
  • I have a public key whose fingerprint is 0D92 1FF5 1FB8 69AB 5B84 469D BDFF 2F6F 0895 870F

To claim this, I am signing this object:

@tiegz
tiegz / uniqlo.rb
Last active July 25, 2021 19:10
uniqlo scraper
require 'json'
require 'pp'
class UniqloProductFetcher
attr_accessor :json
# eg 135779 is pocketable shorts
def initialize(product_id: "135779")
@product_id = product_id
end
@tiegz
tiegz / apa_1616_ir_codes.txt
Last active December 16, 2020 02:18
APA 1616 LED Remote IR Codes
# http://sztyled.en.made-in-china.com/product/SqUmJxylhbhK/China-24-Key-Infrared-RGB-Manual-Flash-Controller-APA-1616-.html
# or
# http://www.dhgate.com/store/product/advanced-micro-control-unit-24-keys-rgb-led/128629434.html
IR Receiver Notes
F700FF BRIGHT HI
F7807F BRIGHT LO
F7408F OFF
F7C03F ON
F720DF R1
@tiegz
tiegz / dup_clone_bench.rb
Created February 18, 2015 15:24
Hash#dup/clone benches
require 'benchmark'
GC.disable
x = {:a => 1}
ms1 = 1000 * Benchmark.realtime { 1_000_000.times { x.dup } }
ms2 = 1000 * Benchmark.realtime { 1_000_000.times { x.clone } }
puts [
@tiegz
tiegz / profile_assets.rb
Created January 5, 2015 20:15
Example ruby-prof middleware
# config/initializers/profile_assets_middleware.rb
Kickstarter::Application.config.middleware.insert_before "Ksr::AuthenticatedRaindrops",
"ProfileAssetsMiddleware"
@tiegz
tiegz / estimate_i18n_string_size.rb
Last active August 29, 2015 14:11
Estimate I18n translations string size.
get_size = ->(memo,val) {
memo + case val
when String
val.bytes.size
when Hash
val.map { |k,v| get_size[0, k] + get_size[0, v] }.sum
when Array
val.map { |v| get_size[0, v] }.sum
when nil, true, false, Fixnum, Symbol
0
@tiegz
tiegz / unused_rails_routes.rb
Created September 3, 2014 18:26
Find unused rails routes
# There could likely be some false positives from this
Rails.application.routes.routes.select do |r|
name = r.defaults[:controller].to_s.classify + "Controller"
klass = name.constantize rescue nil
if klass.nil?
name = r.defaults[:controller].to_s.classify.pluralize + "Controller"
klass = name.constantize rescue nil
end
@tiegz
tiegz / expendables_cast_growth_rate.rb
Last active August 29, 2015 14:04
Growth rate of Expendables cast movie one-liner in Ruby
> ((((Nokogiri::HTML(open("http://en.wikipedia.org/wiki/The_Expendables_(film_series)#Cast_and_characters").read) / "#Cast_and_characters").first.parent.next_element) / "tr")[1..-1].map { |tr| (tr / "td").map { |td| td['colspan'].to_i > 0 ? ([td.text] * td['colspan'].to_i) : td.text } }).map(&:flatten).tap { |a| (0..2).map { |i| a.map { |row| row[i].blank? ? 0 : 1 }.sum }.tap { |a| puts "1->2: #{(a[1] - a[0]) / a[0].to_f}%"; pus "2->3: #{(a[2] - a[1]) / a[1].to_f}%" } } nil
1->2: 0.0
2->3: 0.26666666666666666
@tiegz
tiegz / object_profiler.rb
Last active August 29, 2015 14:03
Object Profiler for ruby 2.1.0+
module ObjectSpace
def self.profile(&blk)
require 'objspace'
enable_gc = GC.disable
ObjectSpace.trace_object_allocations(&blk)
objs = Hash.new(0)
ObjectSpace.each_object { |o|
if (file = ObjectSpace.allocation_sourcefile(o)) && (line = ObjectSpace.allocation_sourceline(o))
objs["#{file}:#{line}:#{o.class.name}"] += 1