Skip to content

Instantly share code, notes, and snippets.

View branch14's full-sized avatar

Phil Hofmann branch14

View GitHub Profile
require 'gsl'
a = [0,1,2,3,4,8]
v = GSL::Vector.alloc(a).sort
q1 = v.quantile_from_sorted_data(0.25)
q3 = v.quantile_from_sorted_data(0.75)
iqr = q3 - q1
tw = q3 + iqr * 1.5
bw = q1 - iqr * 1.5
to = a.filter { |x| x > tw }
@branch14
branch14 / proxy_map.clj
Last active May 27, 2017 08:41
Problem with proxy of PersistentArrayMap
(defn with-fallback [amap fallback-fn]
(proxy [clojure.lang.PersistentArrayMap
clojure.lang.IFn]
[(into-array Object amap)]
(invoke [key] (or (get amap key)
(fallback-fn amap key)))))
(def a (with-fallback {:a 1}
(fn [amap key] (str "no value for " key " in " amap))))
#!/usr/bin/env ruby
require 'json'
require 'uri'
require 'net/http'
URL = '<YOUR INCOMING WEBHOOK URL HERE>'
MESSAGE = {
username: 'monit',
#!/usr/bin/env ruby
Signal.list.each do |signal, number|
begin
print "trapping % -6s ..." % signal
Signal.trap(signal) do
puts 'caught ' + signal
exit
end
puts 'ok.'
Promise = require('bluebird')
cached = null
module.exports = (args) ->
return cached if cached?
cached = Promise.resolve(args)
unless module.parent?
@branch14
branch14 / jessie-on-x1-carbon.sh
Last active December 16, 2015 13:59
install debian jessie on lenovo x1 carbon
# Disable secure boot in the bios security tab.
wget http://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/8.2.0-live+nonfree/amd64/iso-hybrid/debian-live-8.2.0-amd64-standard+nonfree.iso
# Insert USB stick. Check device. Here sdb
cp debian-live-8.2.0-amd64-standard+nonfree.iso /dev/sdb
# Insert usb. Hit F12 on startup to enter the boot menu.
@branch14
branch14 / count_conflicts.rb
Created September 11, 2014 09:24
count conflicts
#!/usr/bin/env ruby
#
# synopsis
#
# ruby merge_locales.rb config/locales translations.yml
require 'yaml'
require 'rubygems'
require 'highline/import'
#!/usr/bin/ruby
require 'optparse'
require 'ostruct'
require 'RMagick'
include Magick
# ------------------------------------------------------------
#!/usr/bin/env ruby
#
# synopsis
#
# ruby merge_locales.rb config/locales translations.yml
require 'yaml'
require 'rubygems'
require 'highline/import'
# config/initializers/i18n.rb
# chain the translations usage tracker into the i18n backend
require File.expand_path('../../../lib/i18n/backend/track_usage', __FILE__)
I18n.backend = I18n::Backend::Chain.new(I18n::Backend::TrackUsage.new, I18n.backend)