Skip to content

Instantly share code, notes, and snippets.

View rickhull's full-sized avatar

Rick Hull rickhull

View GitHub Profile
@rickhull
rickhull / lru-squeeze-mode.el
Created July 13, 2025 02:37
3 columns in emacs, each 80ch wide. except the LRU gets squeezed
;;; lru-squeeze-mode.el --- A mode for LRU-based window resizing
(require 'cl-lib)
(defgroup lru-squeeze-mode nil
"Customization group for LRU Squeeze Mode."
:group 'applications)
(defcustom lru-squeeze-column-count 3
"The number of columns to maintain. Only 2 or 3 are supported."
@rickhull
rickhull / post-chroot.sh
Last active December 2, 2024 02:02
Arch Install
#!/bin/bash
set -e
HOSTNAME="dummy"
IFACE="eth0"
LANG="en_US.UTF-8"
TIMEZONE="America/New_York"
# Hostname
echo $HOSTNAME > /etc/hostname
@rickhull
rickhull / client.rb
Last active September 29, 2024 23:32
Nostr client using async websockets
require 'async'
require 'async/barrier'
require 'async/http/endpoint'
require 'async/websocket/client'
require 'nostrb/source'
module Nostrb
class Client
def initialize(relay_url)
@rickhull
rickhull / pragma.rb
Created September 17, 2024 18:27
SQLite pragma handling
class Pragma
ENUM = {
'auto_vacuum' => %w[none full incremental],
'synchronous' => %w[off normal full],
'temp_store' => %w[default file memory],
}
RO = %w[data_version freelist_count page_count]
RW =
%w[application_id analysis_limit auto_vacuum automatic_index
# https://github.com/Gerg-L/nix-templates/blob/master/devShell%2Fflake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs =
{ nixpkgs, ... }:
{
devShells.x86_64-linux =
let
@rickhull
rickhull / shell.txt
Created March 31, 2024 00:47
gem install ruzzy
[nix-shell:~/git/compsci]$ sh install_ruzzy.sh
<internal:/home/rwh/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require': libyaml-0.so.2: cannot open shared object file: No such file or directory - /home/rwh/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/x86_64-linux/psych.so (LoadError)
from <internal:/home/rwh/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /home/rwh/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/psych.rb:13:in `<top (required)>'
from <internal:/home/rwh/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from <internal:/home/rwh/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
from /home/rwh/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/rubygems.rb:608:in `load_yaml'
from /home/rwh/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/rubygems/config_file.rb:346:in `load_file'
from /home/r
@rickhull
rickhull / bitset_benchmark.rb
Last active March 19, 2024 20:22
bitset benchmark
require 'rbconfig/sizeof' # can we use 64 bit ints?
require 'benchmark/ips'
require 'bitset'
# this should work well up to 64 bits on 64 bit platforms
# using native integers
# beyond that, Bignums will be generated
class BitsInt
attr_reader :int
require 'zlib'
require 'digest'
require 'openssl'
require 'benchmark/ips'
DIGESTS = %w[MD5 SHA1 SHA256 SHA384 SHA512 RMD160].map { |name|
Digest(name).new
}
OPENSSL_DIGESTS = %w[SHA1
@rickhull
rickhull / shell.txt
Last active March 4, 2024 21:09
reproduce Digest::MD5 thread-safe bug
[rwh@nixos:~/code/59774592dbaf12d47fa53d0c29c13e6d]$ ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
[rwh@nixos:~/code/59774592dbaf12d47fa53d0c29c13e6d]$ ruby test_digest.rb
Run options: --seed 50097
# Running:
..........
require 'bitset'
require 'zlib'
class BloomFilter
# just defaults, overrideable
SEED = 0
FPR = 0.01
def self.num_bits(num_items, fpr: FPR)
(-1 * num_items * Math.log(fpr) / Math.log(2) ** 2).ceil