Skip to content

Instantly share code, notes, and snippets.

View mikecmpbll's full-sized avatar
🎯
Focusing

Mike Campbell mikecmpbll

🎯
Focusing
  • Skipton, North Yorkshire
View GitHub Profile
@mikecmpbll
mikecmpbll / _results.log
Created May 22, 2019 22:41
Ruby 2.5.1 number thingy benchmark
Warming up --------------------------------------
maths 50.286k i/100ms
slice map 34.402k i/100ms
multi map 13.137k i/100ms
original 24.600k i/100ms
gsub 14.685k i/100ms
all maths 55.759k i/100ms
readable 14.009k i/100ms
Calculating -------------------------------------
maths 663.215k (± 2.9%) i/s - 3.319M in 5.008728s
module WithLock
def with_lock
lock.owned? ? yield : lock.synchronize{ yield }
end
end
class Mutex
prepend WithLock
end
@mikecmpbll
mikecmpbll / versioning.rake
Last active August 19, 2016 21:08
A wee set of rake tasks to help bump version number using git tags.
LEVELS = [:major, :minor, :patch]
def version
@version ||= begin
v = `git describe --always --tags`
{}.tap do |h|
h[:major], h[:minor], h[:patch], h[:rev], h[:rev_hash] = v[1..-1].split(/[.-]/)
end
end
end
@mikecmpbll
mikecmpbll / knapsack.rb
Last active August 11, 2016 16:24
knapsack ruby
W = 10
v = [17, 1, 5, 15, 9, 2, 10, 8, 5, 16, 3, 17, 3, 3, 18, 12, 18, 20, 18, 8]
w = [5, 1, 4, 3, 4, 2, 1, 3, 2, 5, 3, 4, 1, 5, 2, 4, 5, 2, 3, 5]
n = v.size
m = Array.new(n + 1){ Array.new(W, 0) }
n.times do |i|
W.times do |j|
m[i + 1][j] =
if j + 1 < w[i]
rsyslog:
pkg.installed
service.running:
- watch:
- file: /etc/rsyslog.conf
newrelic:
pkg.installed:
- name: newrelic-sysmond
service.running:
- name: newrelic-sysmond
- enable: True
def recursive_merge!(enum, enum2)
enum2.map do |k, v2|
v = enum[k]
enum[k] =
if v.is_a?(Hash) && v2.is_a?(Hash)
recursive_merge(v, v2)
elsif v.is_a?(Array) && v2.is_a?(Array)
v | v2
else
v2
@mikecmpbll
mikecmpbll / borg_chunker_test.py
Created May 6, 2016 11:11
Testing out the speed of the borg chunker with default chunker params.
import os
import time
from borg.chunker import Chunker
CHUNK_MIN_EXP = 19 # 2**19 == 512kiB
CHUNK_MAX_EXP = 23 # 2**23 == 8MiB
HASH_WINDOW_SIZE = 0xfff # 4095B
HASH_MASK_BITS = 21 # results in ~2MiB chunks statistically
CHUNKER_PARAMS = (CHUNK_MIN_EXP, CHUNK_MAX_EXP, HASH_MASK_BITS, HASH_WINDOW_SIZE)
# proof that rsystemm2 (http://rsystemm2.tumblr.com/) is bullshit
# designed to earn referral money from ladbrokes.
#
# this actually uses a 50% win chance, compared to roulettes 48.6%
# so it should be _more_ profitable than the "system"
# sample output in 2nd file.
def roulette_system
history = []
predicted = nil
@mikecmpbll
mikecmpbll / buzhash.rb
Created February 24, 2016 20:43
Buzhash in Ruby
require 'stringio'
module Meriback
class Buzhash
# should be seeding this
BYTE_HASH = [
0x589c63e9, 0x118d2c7c, 0x1faecf92, 0x53c9f4d8, 0x6c8cb496, 0x35e0af5a, 0x3a786480, 0x035d8045,
0x5e6bd8f7, 0x6932ba3b, 0x59221501, 0x59f92f7e, 0x60ed62ad, 0x044a900e, 0x4357a8a6, 0x0bd7d8ef,
0x7dc25b20, 0x212d52be, 0x033f160f, 0x0cde12b8, 0x400fa76c, 0x26ebec72, 0x59413573, 0x534bdcbb,
0x2b165e74, 0x25ff262d, 0x61aee04d, 0x07f43f1a, 0x306e498f, 0x5a42f52a, 0x63f5a489, 0x6a713fcf,