Skip to content

Instantly share code, notes, and snippets.

View stuartbain's full-sized avatar

Stuart Bain stuartbain

View GitHub Profile
@stuartbain
stuartbain / setup.md
Created May 8, 2022 18:14 — forked from mkontani/setup.md
softhsm x crypki (HSM signer) on Mac brew

setup softhsm

install tools

brew install softhsm opensc

softhsm configs

@stuartbain
stuartbain / radix_info.py
Created May 21, 2021 11:11
Radix Metrics
import sys
import requests
from flatten_json import flatten
content = []
# System Info
system_info = requests.get('http://localhost:3333/system/info')
flat_system_info = flatten(system_info.json())
@stuartbain
stuartbain / je_tuning.md
Created May 19, 2021 16:39 — forked from gbehrmann/je_tuning.md
Berkeley DB pool tuning instructions

First a little background info. The Berkeley DB Java Edition library used by the pools (if so configured) uses a log structured file format. What this means is that the files of the database (called log segments) are only ever appended to. Once they reach a certain size (10 MB by default), a new log segment is created and the previous log segments are never modified. If existing data is modified or deleted, this leaves unused fragments in these these database files. Once the utilization (amount of data still in use) falls under a certain level, remaining data is copied to the end of the last segment and the original segment is deleted (this is all text book log structured database).

Berkeley DB uses a btree structure, i.e. it is structured as a tree, with the actual data at the leafs and the internal nodes allowing fast search of the data.

Berkeley DB internally maintains a cache of the files. The default in dCache is to use 20% of the maximum heap size as a cache for Berkeley DB. It is a recommendation fr

@stuartbain
stuartbain / heroku_name.ex
Created February 7, 2017 01:31
Create Heroku style random names
defmodule HerokuName do
def generate() do
adjectives = [
"autumn", "hidden", "bitter", "misty", "silent", "empty", "dry", "dark",
"summer", "icy", "delicate", "quiet", "white", "cool", "spring", "winter",
"patient", "twilight", "dawn", "crimson", "wispy", "weathered", "blue",
"billowing", "broken", "cold", "damp", "falling", "frosty", "green",
"long", "late", "bold", "little", "morning", "muddy",
"red", "rough", "still", "small", "sparkling", "shy",

Keybase proof

I hereby claim:

  • I am stuartbain on github.
  • I am stuartbain (https://keybase.io/stuartbain) on keybase.
  • I have a public key ASAmMdt8iwTT9VLCcuCJhxAyfFccWPpZL3aTB-qQy50z3Ao

To claim this, I am signing this object:

# https://coderwall.com/p/suyeew
# /app/helpers/devise_helper.rb
module DeviseHelper
def devise_error_messages!
return '' if resource.errors.empty?
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
sentence = I18n.t('errors.messages.not_saved',
@stuartbain
stuartbain / gist:7235213
Created October 30, 2013 16:01
Configure session store domain by Rails environment
MyApp::Application.config.session_store :cookie_store, key: '_my_app_session', domain: {
production: '.example.com',
development: '.example.dev'
}.fetch(Rails.env.to_sym, :all)
@stuartbain
stuartbain / subdomain_validator.rb
Last active October 25, 2021 22:33
Custom validator for Subdomains
class SubdomainValidator < ActiveModel::EachValidator
# http://matthewhutchinson.net/2010/10/27/rails-3-subdomain-validation-activemodeleachvalidator
def validate_each(object, attribute, value)
return unless value.present?
reserved_names = %w(www ftp mail pop smtp admin ssl sftp)
reserved_names = options[:reserved] if options[:reserved]
if reserved_names.include?(value)
object.errors[attribute] << 'cannot be a reserved name'
end
@stuartbain
stuartbain / check_digit.rb
Last active May 21, 2019 09:25
Calculate check digits for SEDOL, CUSIP, ISIN and BBGID (Bloomberg Global Id) codes
module CheckDigit
class SEDOL
SEDOL_WEIGHTS = [1,3,1,7,3,9]
SEDOL_PATTERN = /[B-Db-dF-Hf-hJ-Nj-nP-Tp-tV-Xv-xYyZz\d]{6}/ # http://regexlib.com/REDetails.aspx?regexp_id=1044
def self.calculate(sedol)
raise 'Invalid pattern' unless sedol =~ SEDOL_PATTERN