Skip to content

Instantly share code, notes, and snippets.

View RobinDaugherty's full-sized avatar

Robin Daugherty RobinDaugherty

View GitHub Profile
@RobinDaugherty
RobinDaugherty / performance_comparison.md
Last active March 9, 2016 01:19
Performance comparison of Hash with lru_redux and homegrown binary tree

This is an analysis of the existing Widget PinCache performance trying different storage objects. The baseline is the implementation that uses LruRedux::TTL::Cache (which is not the threadsafe version).

I tried replacing this with a native Ruby Hash, and in the case of the negative cache, I also tried instead replacing it with a native Set object.

I also tried the same using a binary tree implemented within the Ruby interpreter.

Profiling was done with JRuby 1.7.22 in Ruby 2.0 mode. The process was restarted before each run.

1/5 Cache Hit Rate, 20% Negative Response Rate

@RobinDaugherty
RobinDaugherty / find_the_breaking_commit.sh
Created February 13, 2016 01:37
Find the breaking commit
# Start with a broken commit, this will walk back to the first working commit.
until bundle; do
cd ../rubygems
git reset --hard HEAD^
ruby setup.rb --no-document
cd ../jruby-test
done
$ dig rubygems.org
; <<>> DiG 9.9.5-3ubuntu0.7-Ubuntu <<>> rubygems.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10778
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
@RobinDaugherty
RobinDaugherty / rubygems-failure-to-connect.txt
Created February 11, 2016 21:43
Rubygems server failing
$ wget https://rubygems.org/gems/rake-10.5.0.gem
--2016-02-11 21:30:29-- https://rubygems.org/gems/rake-10.5.0.gem
Resolving rubygems.org (rubygems.org)... 54.186.104.15
Connecting to rubygems.org (rubygems.org)|54.186.104.15|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://rubygems.global.ssl.fastly.net/gems/rake-10.5.0.gem [following]
--2016-02-11 21:30:30-- https://rubygems.global.ssl.fastly.net/gems/rake-10.5.0.gem
Resolving rubygems.global.ssl.fastly.net (rubygems.global.ssl.fastly.net)... 185.31.19.249, 185.31.18.249
Connecting to rubygems.global.ssl.fastly.net (rubygems.global.ssl.fastly.net)|185.31.19.249|:443... connected.
HTTP request sent, awaiting response... 200 OK
  1. check the cache and return the value if found
  2. with mutex locked 1. if the ID is currently in flight, get its condition variable 2. if ID is not in flight, check the cache again for the item
    1. if it was in the cache, return the item
    2. if not in the cache
    3. if there's room for another in-flight request 1. add a condition variable to the list of in-flight requests
  3. if the ID was already in flight, wait on the condition variable we got for it
  4. when the condition variable signals, return the item from the cache
module Concerns
module HasOneAutoCreated
extend ActiveSupport::Concern
module ClassMethods
def has_one_auto_created(association_name, options = {})
has_one association_name, options
alias_method "existing_#{association_name}", association_name
@RobinDaugherty
RobinDaugherty / create_gadgets.rb
Created February 1, 2016 04:20
ActiveRecord attribute serializer Hashie::Mash stored as a JSON string in Postgres
class CreateGadgets < ActiveRecord::Migration
def change
create_table "gadgets" do |t|
t.string "info"
end
end
end
@RobinDaugherty
RobinDaugherty / create_gadgets.rb
Last active October 19, 2022 14:22
ActiveRecord attribute serializer Hashie::Mash stored as JSON in Postgres
class CreateGadgets < ActiveRecord::Migration
def change
create_table "gadgets" do |t|
t.json "info"
end
end
end
@RobinDaugherty
RobinDaugherty / gist:3c92f7427794b7ffa22a
Last active January 4, 2016 17:25
Install php-cgi with Homebrew
brew tap josegonzalez/homebrew-php
brew tap homebrew/dupes
brew install --enable-cgi php56
@RobinDaugherty
RobinDaugherty / github_api_issues.rb
Last active December 23, 2015 02:49
Close Github issues with a certain label
require 'github_api'
github = Github.new(
oauth_token: 'fill-me-in',
auto_pagination: true,
)
# Returns ALL OPEN ISSUES. Learned the hard way that the `label` parameter does nothing here.
open_issues = github.issues.list(user: 'lemurheavy', repo: 'coveralls', state: 'open')