Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Mike Campbell mikecmpbll

🎯
Focusing
Block or report user

Report or block mikecmpbll

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mikecmpbll
mikecmpbll / _results.log
Created May 22, 2019
Ruby 2.5.1 number thingy benchmark
View _results.log
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
View with_lock.rb
module WithLock
def with_lock
lock.owned? ? yield : lock.synchronize{ yield }
end
end
class Mutex
prepend WithLock
end
@mikecmpbll
mikecmpbll / knapsack.rb
Last active Aug 11, 2016
knapsack ruby
View knapsack.rb
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]
View rsyslog.sls
rsyslog:
pkg.installed
service.running:
- watch:
- file: /etc/rsyslog.conf
View one.sls
newrelic:
pkg.installed:
- name: newrelic-sysmond
service.running:
- name: newrelic-sysmond
- enable: True
View recursive_merge.rb
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
Testing out the speed of the borg chunker with default chunker params.
View borg_chunker_test.py
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)
View buzhash.rb
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,
View eg.rb
class Whatever
attr_accessor :error
def grava_lead(attrs)
if some_condition
@error = "Some error"
return false
end
# ...
end
@mikecmpbll
mikecmpbll / self_contained.rb
Last active Jan 14, 2016
scope on habtm completely fucked when including?
View self_contained.rb
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
You can’t perform that action at this time.