Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
puts "looking for the gems to upgrade..."
gem_info = Struct.new(:name, :version)
to_reinstall = []
Dir.glob('/opt/local/lib/ruby/gems/**/*.bundle').map do |path|
path =~ /.*1.8\/gems\/(.*)-(.*?)\/.*/
name, version = $1, $2
bundle_info = `file #{path}`
to_reinstall << gem_info.new(name, version) unless bundle_info =~ /bundle x86_64/
end
# following is a little benchmark looking a real world example of inserting a
# bunch of records into pg and mongo using a few methods available in ruby.
# this is not meant to be an apples to apples benchmark, rather it's trying to
# see how the various dbs might perform in a real world situation. i know
# mongo does not fsync to disk. i know it's not fair using a transaction with
# the rdbms, but these conditions will exist in real world usage and it's that
# which i'm interested in.
#
# here is a few runs
#
@bhb
bhb / gist:6116481
Last active December 20, 2015 10:31 — forked from caius/gist:6002173
# -*- coding: utf-8 -*-
require "addressable/uri"
require "uri"
def uri_valid?(uri)
uri = Addressable::URI.parse(uri)
# If it could not be parsed, it won't have a valid scheme
%w{http https}.include?(uri.scheme)
rescue Addressable::URI::InvalidURIError
false
@bhb
bhb / reagent-state-bidi-input.cljs
Last active June 13, 2017 22:51 — forked from pesterhazy/00-reagent-state-bidi-input.md
Reagent input field experiments in bidirectional binding
(ns klipse-like.core
(:require [reagent.core :as r])
(:import [goog.async Delay]))
(enable-console-print!)
(defonce !state (r/atom nil))
(defn input*
"Like :input, but support on-change-text prop. Avoids mutability pitfalls of
@bhb
bhb / multimethod_selector.clj
Last active November 13, 2019 10:22 — forked from mtnygard/multimethod_selector.clj
A clojure.spec.gen.alpha generator that picks a multimethod implementation from the known set.
(require '[clojure.spec.gen.alpha :as sgen])
;; original
(defn multimethod-selector
"Returns a generator that picks one dispatch value from the known
dispatch values of a multimethod. Defers the lookup of dispatch
values until sampling time, so any defmethods evaluated after the
generator is created may still be selected."
[s]
#(sgen/bind
@bhb
bhb / init.cljs
Last active November 7, 2018 03:26 — forked from borkdude/init.cljs
Speculative + Expound in Klipse
(require '[cljs.spec.alpha :as s])
(require '[cljs.spec.test.alpha :as stest])
(require '[expound.alpha :as expound])
(require '[speculative.core])
(set! s/*explain-out* (expound/custom-printer {:show-valid-values? true}))
(stest/instrument `map)
(try
(map 'lol 'lol)
(catch :default e
(println (.-message e))))
[{"loan":{"id":1,"borrower_id":1,"amount":10984659,"term":120},"period":{"start_at":"2017-05-22T00:00:00-06:00","end_at":"2017-06-21T23:59:59-06:00"},"principal":57702,"interest":83752,"rate_annual":900,"service_fee":{"amount":0,"rate":0}},{"loan":{"id":1,"borrower_id":1,"amount":10984659,"term":120},"period":{"start_at":"2017-06-22T00:00:00-06:00","end_at":"2017-07-21T23:59:59-06:00"},"principal":56262,"interest":80629,"rate_annual":900,"service_fee":{"amount":0,"rate":0}},{"loan":{"id":1,"borrower_id":1,"amount":10984659,"term":120},"period":{"start_at":"2017-07-22T00:00:00-06:00","end_at":"2017-08-21T23:59:59-06:00"},"principal":58577,"interest":82877,"rate_annual":900,"service_fee":{"amount":0,"rate":0}},{"loan":{"id":1,"borrower_id":1,"amount":10984659,"term":120},"period":{"start_at":"2017-08-22T00:00:00-06:00","end_at":"2017-09-21T23:59:59-06:00"},"principal":59026,"interest":82428,"rate_annual":900,"service_fee":{"amount":0,"rate":0}},{"loan":{"id":1,"borrower_id":1,"amount":10984659,"term":120},"peri