Skip to content

Instantly share code, notes, and snippets.

View ms-ati's full-sized avatar

Marc Siegel ms-ati

  • American Technology Innovations
  • Boston, MA
  • X @ms_ati
View GitHub Profile
@ms-ati
ms-ati / test_inotify.rb
Last active July 11, 2018 14:58 — forked from e2/test_inotify.rb
Script for testing inotify and listen on Linux
gem "rb-inotify"
require 'rb-inotify'
gem "listen"
require "listen"
# BEGIN MONKEY PATCH OF LISTEN GEM
Listen::Adapter::Linux::DEFAULTS.tap do |defaults|
# Add :modify to the inotify events monitored by the Linux adapter
new_defaults = defaults.merge(events: defaults[:events] + [:modify])
@ms-ati
ms-ati / Dinghy_test_fixes_for_APFS_notes.md
Last active May 8, 2018 20:18
Note on resolving nanosecond timestamp issues in Dinghy
  1. Reviewed How To Open a Homebrew Pull Request

    a. Forked codekitchen/homebrew-dinghy on Github to ms-ati/homebrew-dinghy

    b. Changed to directory containing the Dinghy tap: cd $(brew --repository codekitchen/dinghy)

    c. Added my fork as a remote: git remote add ms-ati https://github.com/ms-ati/homebrew-dinghy.git

    d. Checked out the master branch: git checkout master

##
# Monkey-patch IRB in Ruby 2.3.4 to address the following Ruby issue:
#
# * https://bugs.ruby-lang.org/issues/14685
# IRB doesn't print exception cause
##
# After loading this file, one should observe in an IRB session:
#
# * Printed exceptions contain the `#cause`
# In fact, this should work for a chain of `#cause` relationships
@ms-ati
ms-ati / bench_bigdecimal_from_float.rb
Created November 20, 2017 18:00
Benchmark "sigfigs" parameter to BigDecimal constructor given a Float
require "benchmark/ips"
require "bigdecimal"
FLOATS = [1.35, 2.35, 3.35, 4.35, 5.35, 6.35, 7.35].freeze
STRINGS = ["1.4", "2.4", "3.4", "4.4", "5.4", "6.4", "7.4"].freeze
FULL = BigDecimal.double_fig
PART = 3
def full_precision
@ms-ati
ms-ati / selectable_queue.rb
Created September 28, 2017 17:00 — forked from garybernhardt/selectable_queue.rb
A queue that you can pass to IO.select.
# A queue that you can pass to IO.select.
#
# NOT THREAD SAFE: Only one thread should write; only one thread should read.
#
# Purpose:
# Allow easy integration of data-producing threads into event loops. The
# queue will be readable from select's perspective as long as there are
# objects in the queue.
#
# Implementation:
@ms-ati
ms-ati / ruby_fast_case_when_set.rb
Created August 10, 2017 19:51
What's the fast way to find a constant set of values in a ruby case statement?
# frozen_string_literal: true
#
# What's the fast way to find a constant set of values in a ruby case statement?
#
require "benchmark/ips"
require "set"
# Provides a `===` operator for a Set
class SetCaseEq
@ms-ati
ms-ati / ruby_fast_choose_article.rb
Last active August 1, 2017 15:27
What's the fast way to choose "a" vs "an" English article in Ruby?
# frozen_string_literal: true
#
# What's the fast way to choose "a" vs "an" English article in Ruby?
#
# Based on / inspired by: https://github.com/JuanitoFatas/fast-ruby/blob/master/code/string/start-string-checking-match-vs-start_with.rb
# See more at https://github.com/JuanitoFatas/fast-ruby
#
require 'benchmark/ips'
@ms-ati
ms-ati / benchmark_values_eql.rb
Created April 7, 2017 20:02
Benchmark proposed optimization to `#eql?` method in Values gem
require "benchmark/ips" # gem install benchmark-ips
require "values"
fields = [:a, :b, :c, :d, :e, :f, :g]
# Current code
a = Value.new(*fields)
# Code with optimized `#eql?`
b = Value.new(*fields) do
@ms-ati
ms-ati / benchmark_values_with_opt.rb
Created March 22, 2017 14:10
Benchmarks showing optimization of `#with` in Values gem
# Simple immutable value objects for ruby.
#
# @example Make a new value class:
# Point = Value.new(:x, :y)
#
# @example And use it:
# p = Point.new(1, 0)
# p.x
# #=> 1
# p.y
# Workaround for https://github.com/ruby-concurrency/concurrent-ruby/issues/611
#
# This approach works to *lazily* compose a chained future of
# sequential steps, where each step is a *zipped* future of a
# set of futures to execute in parallel at that step.
#
# Works with:
#
# gem install concurrent-ruby-edge -v 0.2.3.pre3
#