Skip to content

Instantly share code, notes, and snippets.

View havenwood's full-sized avatar
:octocat:

Shannon Skipper havenwood

:octocat:
  • Ashland, Oregon
  • 11:44 (UTC -07:00)
View GitHub Profile
@havenwood
havenwood / trad_sleep.rb
Created May 8, 2025 23:12
Just a sleep-alarm based thingy for an IRC example
signal = 'ALRM'
status = Signal.list.fetch(signal) + 2**7
pid = fork do
trap signal do
warn 'Alarm!'
exit status
end
sleep
@havenwood
havenwood / zipped_io.rb
Created April 27, 2025 21:12
Just a fun example for Ruby IRC playing with IO.copy_stream
require 'stringio'
require 'zlib'
io = StringIO.new('Zip me...')
zipped_io = StringIO.new('', 'a+b')
writer = Zlib::GzipWriter.new(zipped_io)
IO.copy_stream(io, writer)
writer.finish
zipped_io.rewind
@havenwood
havenwood / sync_pipe.rb
Created March 23, 2025 04:18
An example refinement method like `IO.pipe`'s block form but with no buffering.
class IO
module UnbufferedPipe
refine IO.superclass do
def unbuffered_pipe(*, **)
IO.pipe(*, **) do |read_io, write_io|
read_io.sync = true
write_io.sync = true
yield read_io, write_io
end
@havenwood
havenwood / ppp
Created March 14, 2025 06:45
`ppp` is a zsh script for inspecting basic filename whitespace
#!/usr/bin/env -S zsh -e
help() {
print -u2 -- "Usage: $ZSH_ARGZERO [options] [directory...]
Options:
-h, --help Output this help message
-v, --version Output program name and version"
exit ${1:-0}
}
@havenwood
havenwood / wired
Created March 3, 2025 18:20
Adjust wired limits to allocate more memory to the GPU with Apple Silicon
#!/usr/bin/env -S zsh -e
zparseopts -D -F -- \
g:=opt_gb -reserve-gb:=opt_gb \
p:=opt_percent -reclaim-percent:=opt_percent \
h=opt_help -help=opt_help \
v=opt_version -version=opt_version
if (( ${#opt_help} )); then
print -- "Usage: $(basename $0) [options]
@havenwood
havenwood / factorial.rb
Last active March 5, 2025 04:59
An example Ruby unary method implementation of a Schönhage–Strassen optimized factorial
##
# This refinement uses a binary-splitting algorithm for fairly
# efficient factorial calculation with results cached by default.
#
# Caching dramatically improves performance when portions of the
# factorial calculation are repeated.
class UnaryFactorial < Module
class NegativeError < StandardError
def initialize(message = 'Factorials cannot be negative') = super
end
@havenwood
havenwood / map.rb
Created February 16, 2025 00:31
A Ractor-backed `Map` riffing on https://bugs.ruby-lang.org/issues/21121#note-1
class Ractor
module Channel
def self.new(&block)
channel = Ractor.new do
loop do
Ractor.yield Ractor.receive
end
end
return block.call(channel) if block_given?
@havenwood
havenwood / models.md
Last active March 12, 2025 22:39
LLM models high level overview

Models

In order to offload to GPU a model must fit in VRAM.

The following table lists models assuming Q4_K_M quantization. You can always use a model that fits in a smaller VRAM size.

VRAM Models
384GB - DeepSeek V3 671
128GB - Mistral Large 2411 123b
64GB - Qwen2.5 72b
@havenwood
havenwood / data_literal.rb
Created January 9, 2025 16:41
A `~{meaning: 42}`-style Data literal implemented in Ruby
module DataLiteral
refine Hash do
def to_data(name = nil)
if name
unless Object.const_defined?(name)
Object.const_set(name, Data.define(*keys))
end
Object.const_get(name).new(*values)
else
@havenwood
havenwood / install-ruby-3.4.1-mmtk.sh
Last active December 25, 2024 09:48
A little script to install Ruby 3.4.0 with the experimental MMTk garbage collector
#!/usr/bin/env zsh -e
version=3.4.1
brew install gmp jemalloc libffi libyaml openssl@3 readline zlib
command -v rustc >/dev/null 2>&1 || brew install rust
mkdir -p "$HOME/src"
cd "$HOME/src"
curl "https://cache.ruby-lang.org/pub/ruby/3.4/ruby-$version.tar.xz" | tar -x
cd "ruby-$version"