Skip to content

Instantly share code, notes, and snippets.

View krisleech's full-sized avatar

Kris Leech krisleech

View GitHub Profile
@krisleech
krisleech / renew-gpgkey.md
Last active April 1, 2026 05:06
Renew Expired GPG key

Renew GPG key

Given that your key has expired.

$ gpg --list-keys
$ gpg --edit-key KEYID

Use the expire command to set a new expire date:

@krisleech
krisleech / readme.md
Created February 4, 2026 15:27
Dynamic Consistency Boundary (conditional put options)

Conditional Put: Three Approaches Compared

1. Our Approach (Serializable Snapshot Isolation)

Repo.transaction(
  fn ->
    if has_events_since?(filters, max_position) do
      Repo.rollback(:inconsistent)
    else
@krisleech
krisleech / 00-NOTES.md
Last active January 22, 2026 05:37
Notes on Clojure ring handlers and middleware

Ring handler a function which accepts a request (map) and returns a response (map).

Ring middleware

function (handler, &args -> function(request -> response) because it is a closure handler and &args are in scope within the returned handler function.

a function which accepts a "next handler" (the next handler in the chain) + any extra arguments and returns a handler (function), which will accept a request and return a response.

@krisleech
krisleech / clipboard.md
Last active November 27, 2025 11:43
3 ways to copy to clipboard in Javascript
if(document.queryCommandSupported('copy')) {
        if(text=='') { text = ' '; } // empty inputs do not get selected

        // copy text to off-screen input
        $('#clipboard').val(text);

        // 1.) does copy empty inputs, but adds newline before content
        var range = document.createRange();
 range.selectNode(document.querySelector('#clipboard'));
@krisleech
krisleech / prop.md
Last active October 20, 2025 11:32
Switchable Elixir adapter

Proposal to allow adapters to be switched at runtime in tests.

Example:

We have an EntityStore which has functions to save and find entities.

In our tests we want the ability to use different implimentations (real, dummy, in-memory etc.) in different tests.

We might want to use the real adapter in acceptance tests, a dummy one just to assert the adapter is called, and an in-memory adapter for all other tests (because it's faster).

@krisleech
krisleech / HOWTO.md
Last active December 31, 2024 12:47
ActiveModel comforming Form object based on dry-type / dry-validation
require 'dry-validation'
require 'dry-struct'
require 'active_model/errors'

require_relative '../create_study'

module MyApp
  module Types
    include Dry::Types.module
@krisleech
krisleech / 00-README.md
Created August 3, 2017 11:43
UptimeRobot Ansible and v2 API notes

When an interger is sent for monitor>type an internal error occurs. If a string is sent as in the main.yml example it is okay.

When an internal error occurs a 200 response not 500 is sent.

When an error occurs (e.g. monitor already exists) a 200 response is sent.

@krisleech
krisleech / steps.md
Last active December 12, 2023 23:36
Convert Postgres to MySQL

Software:

Steps

  • dump and gzip postgres (source)
pg_dump -Ox -T sessions -U mos mos_staging > ~/mos_staging.sql
@krisleech
krisleech / INFO.md
Created July 6, 2023 16:00
Re-signing an expired certificate for publishing gems
$ gem build wisper.gemspec
Enter PEM pass phrase:
INFO:  Your certificate has expired, trying to re-sign it...
ERROR:  While executing gem ... (Gem::Security::Exception)
    certificate /CN=kris.leech\/DC=gmail\/DC=com not valid after 2020-10-15 18:13:45 UTC   
$ gem cert --re-sign -C gem-public_cert.pem -K ~/.ssh/gem-private_key.pem
@krisleech
krisleech / spec.rb
Created April 24, 2023 16:10
ephemeral ActiveRecord model for specs
let(:model_class) do
Class.new(ApplicationRecord) do
self.table_name = "model_class_#{SecureRandom.uuid.delete('-')}"
def self.up
connection.execute("CREATE TABLE #{table_name}(id INTEGER PRIMARY KEY AUTOINCREMENT)")
end
def self.down
ApplicationRecord.connection.execute("DROP TABLE #{table_name}")