Skip to content

Instantly share code, notes, and snippets.

View mykoweb's full-sized avatar

Mike Kim mykoweb

  • Clearbit
  • San Francisco, CA
View GitHub Profile
@mykoweb
mykoweb / create_alias.rb
Last active December 15, 2016 06:19
Scaling Elasticsearch
req_body_for_patient_a = {
routing: 'PatientA',
filter: {
term: { patient_name: 'PatientA' }
}
}
req_body_for_patient_b = {
routing: 'PatientB',
filter: {
@mykoweb
mykoweb / cpu_bound1.rb
Last active December 20, 2016 00:31
2016-12-15-io-bound-threads-in-ruby
require 'benchmark'
@threads = []
Benchmark.bm(14) do |x|
x.report('no-threads') do
8.times do
tmp_array = []
10_000_000.times { |n| tmp_array << n }
end
end
@mykoweb
mykoweb / gist:e548236770af27147069
Last active August 29, 2015 14:27
Strongly connected components solution
class Lecture04
attr_accessor :graph_reverse, :explored, :number_nodes_processed, :current_source_vertex, :finishing_times, :leaders, :new_graph, :directory
def initialize(dir)
@directory = dir
@graph_reverse = {}
File.foreach(@directory) do |line|
current_edge = line.strip.split.reverse.map(&:to_i)
@graph_reverse[current_edge[0].to_s] = [] if @graph_reverse[current_edge[0].to_s].nil?
@graph_reverse[current_edge[0].to_s] << current_edge[1]
# With this algorithm, we merge/contract the head into the tail
# vertex, i.e., copy edges of head vertex into the tail vertex
# and then delete the head vertex.
adj_list = {}
file = File.read('./kargerMinCut.txt');nil
file.each_line do |line|
line_array = line.strip.split
vertex = line_array.shift
adj_list[vertex.to_s] = line_array
@mykoweb
mykoweb / gist:e0b14986b0d8dcb39589
Last active August 29, 2015 14:25
Steps to debug ruby/sidekiq memory leaks
Some helpful links:
http://samsaffron.com/archive/2015/03/31/debugging-memory-leaks-in-ruby
sudo bundle exec rbtrace -p 27031 -e 'load "/home/mkim/heap-dump.rb"' --timeout 300
["902df967-5e27-49d4-8f6e-254a94777337", "2d4227d5-fffd-4420-b2c6-97e54a6bc8e6", "07c07581-0272-4279-87b2-6c25359cdc1c", "3204575e-b5fd-44dc-9a89-93c1668751ac", "7ce4cbde-a381-491e-9f71-9d04cc1cb438", "8fd03e14-32b3-4160-a08b-b4ca2a44e4c4", "bf5f0ce2-c5ba-4dde-be34-69175383eb16", "90085729-3e24-4b70-8903-db3c31390473", "5f318be7-214a-4573-9684-e5f6e09e5c53", "b6707c1c-2825-4975-8fc8-cff8c654cf9b", "c57594da-3b6e-4e0b-acfd-f5c13c82def5", "64c77f61-24bb-4a89-8b0c-37da0bbf750b", "c397f5b8-41e2-44e5-9d7a-a92b414324a9", "bd78ca99-4a5d-462d-9fb8-abe1fcf76437", "fe831923-8582-4816-9402-1de7de8b48c9", "ab98b096-46b8-4edb-a0a1-1df9fc325529", "32bb06c2-fbb8-49ab-8dd2-748d9d2455b0", "2123c63e-ceb2-48b8-b167-f7e2cb652350", "2b8b6cc9-429f-4325-add5-cdf8cd321c42", "2fb6d295-ef6e-4a6e-a708-16c96b150cd3"]