Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View rickhull's full-sized avatar

Rick Hull rickhull

View GitHub Profile
@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
@rickhull
rickhull / happy_eyeballs.rb
Last active February 8, 2023 01:36
Happy Eyeballs
require 'thread'
class ThreadInterrupt < RuntimeError; end
def try_ip
if rand(2).zero?
sleep 0.5
true
else
sleep(rand(5) + 1)
@rickhull
rickhull / output.txt
Last active January 17, 2023 01:20
What are the available Unix Socket types in Ruby (on Linux)?
best [:SOCK_STREAM, :SOCK_DGRAM, :SOCK_SEQPACKET]
:SOCK_STREAM TYPE SOCK_STREAM
:SOCK_DGRAM TYPE SOCK_DGRAM
:SOCK_SEQPACKET TYPE SOCK_SEQPACKET
other [nil, :SOCK_RAW]
nil TYPE SOCK_STREAM
:SOCK_RAW TYPE SOCK_DGRAM
unsupported [:SOCK_RDM, :SOCK_PACKET, :SOCK_NONBLOCK, :SOCK_CLOEXEC]
@rickhull
rickhull / configuration.nix
Last active February 28, 2024 04:55
Prometheus, Grafana, Loki, Promtail on NixOS
# MONITORING: services run on loopback interface
# nginx reverse proxy exposes services to network
# - grafana:3010
# - prometheus:3020
# - loki:3030
# - promtail:3031
# prometheus: port 3020 (8020)
#
services.prometheus = {
@rickhull
rickhull / shell.nix
Last active July 5, 2020 22:33
shell.nix that prepares tildes for pytest
with import <nixpkgs> {};
with python3Packages;
let
testing_common_database = buildPythonPackage rec {
pname = "testing.common.database";
version = "2.0.3";
src = fetchPypi {
inherit pname version;
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix