Skip to content

Instantly share code, notes, and snippets.

Justin Ko justinko

Block or report user

Report or block justinko

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

Keybase proof

I hereby claim:

  • I am justinko on github.
  • I am jko170 ( on keybase.
  • I have a public key whose fingerprint is 01F0 22A4 834B B3C4 FF22 4029 EEF7 D932 65EA 5E49

To claim this, I am signing this object:

justinko / roman_numeral_calculator.rb
Last active Jun 4, 2017
Roman Numeral Calculator
View roman_numeral_calculator.rb
require 'rspec/autorun'
class RomanNumeralCalculator
1 => 'I',
4 => 'IV',
5 => 'V',
9 => 'IX',
10 => 'X',
40 => 'XL',
View merge_string.rb
def merge_string(a, b)
[a, b].map(&:size).max.times.with_object('') do |(index), output|
[a, b].each {|var| output << (var[index] || '') }
justinko / distributed_mutex.rb
Created May 9, 2017
Distributed Mutex with sidekiq-ent
View distributed_mutex.rb
class DistributedMutex
Blocked =
wait_timeout: 0,
lock_timeout: 30,
policy: :raise,
ttl: 1.hour
justinko / realtime.rb
Created Jun 12, 2014
Ghetto Benchmark Function
View realtime.rb
require 'benchmark'
def realtime(message = nil, count: 1, &block)
results = []
count.times { results << Benchmark.realtime(&block) }
puts message if message
puts results.sum / results.size.to_f
justinko / api_versioning.rb
Last active Aug 29, 2015
Inheritance based API versioning in Rails
View api_versioning.rb
class ApiVersioning
class Middleware
def initialize(app)
@app = app
def call(env)
if version_number = extract_version_number(env)
ApiVersioning.current_version_number = version_number.to_i
Rails.application.eager_load! unless Rails.application.config.cache_classes
justinko / output.txt
Last active Dec 21, 2015
Parse streaming JSON
View output.txt
[3] pry(main)> streaming_json =
=> #<StreamingJSON:0x007fe222b9d8e8
@nesting=#<StreamingJSON::Buffer::Nesting:0x007fe222b9d7d0 @level=0>,
[4] pry(main)> streaming_json[%({"a":)]
=> []
justinko / mongo_aggregation.rb
Created Jun 10, 2013
Demonstrate MongoDB aggregation with the Ruby Mongoid gem.
View mongo_aggregation.rb
require 'mongoid'
require 'pp'
Mongoid.configure do |config|
config.allow_dynamic_fields = false
config.connect_to 'mongo_test', { consistency: :strong }
View .rspec
-I app
View baseball_stats.rb
require 'rubygems'
require 'sequel'
require 'csv'
def parse_data(file_name), headers: :first_row).to_a
db = Sequel.sqlite
You can’t perform that action at this time.