Skip to content

Instantly share code, notes, and snippets.

@codekitchen
codekitchen / 1brc_ractors.rb
Last active January 15, 2024 19:45
Exploring the 1BRC in Ruby with Ractors
#!/usr/bin/env ruby --yjit
WORKER_THREADS = 4
CHUNK_SIZE = 2**16
# BUG: my city struct is being corrupted when moving from the worker to the main ractor.
# `#<struct City min=-11.3, tot=24088.30000000004, max=64.6, n=1164>` becomes
# `#<struct City min=-11.3, tot=24088.30000000004, max=64.6, n=nil>`, note that each `n` attribute becomes `nil`.
# https://bugs.ruby-lang.org/issues/20165
# I tried changing the Struct to a simple array and still using `move: true`,
@codekitchen
codekitchen / hashlife.rb
Last active December 23, 2023 13:14
HashLife implementation for Advent of Code 2023 day 21
# To the extent possible under law, the author(s) have dedicated all copyright and related
# and neighboring rights to this software to the public domain worldwide. This software is
# distributed without any warranty.
# Implementation of the HashLife algorithm for cellular automaton similar to the Game of Life.
# This implementation supports stepping to an arbitrary timestep, not just a power of 2
# time step.
# This implementation also supports loading an infinite tiling "background" of arbitrary
# size to set the initial state of the simulation at any queried position.
# References:
@codekitchen
codekitchen / 11.rb
Last active December 11, 2023 15:29
def part1(input)
g = input.lines.map { _1.strip.chars }
es = g.each_with_index.map { |l,i| i if l.all? { _1 == '.' } }.compact
es.reverse.each { |i| g.insert(i, g[i]) }
g = g.transpose
es = g.each_with_index.map { |l,i| i if l.all? { _1 == '.' } }.compact
es.reverse.each { |i| g.insert(i, g[i]) }
g = g.transpose
g = Grid.new(g.first.size, g.size, g.join)
const express = require('express')
const AWSXRay = require('aws-xray-sdk')
let app = express()
app.use(AWSXRay.express.openSegment('repro'))
// middleware between openSegment() and app routes
app.use((req, res, next) => {
let seg = AWSXRay.getSegment()
res.header('X-Amzn-Trace-Id', seg.trace_id)
seg.setUser(req.headers['user-agent'])
@codekitchen
codekitchen / Dockerfile
Created December 23, 2020 16:05
pipeline Dockerfile
FROM ubuntu:20.04 as build
RUN set -e; \
apt-get update; \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
autoconf \
build-essential \
git \
libreadline-dev \
libncurses5-dev \
@codekitchen
codekitchen / brews.json
Last active August 19, 2020 02:32
brews
{
"yeasts": [
{
"id": "Wyeast 1084",
"name": "Irish Ale",
"attenuation": "73%",
"flocculation": "Medium",
"tolerance": null,
"temp_low": null,
"temp_high": null
@codekitchen
codekitchen / Dockerfile
Created November 12, 2019 01:51
compool dockerfile
FROM node:10
LABEL maintainer="Brian Palmer <brian@codekitchen.net>"
RUN mkdir /root/homebridge
WORKDIR /root/homebridge
RUN npm install homebridge serialport
RUN npm install \
git+https://github.com/codekitchen/node-compool-controller \
git+https://github.com/codekitchen/homebridge-compool
FROM jwilder/nginx-proxy
COPY *.conf /etc/nginx/conf.d/
COPY letsencrypt.diff /app/
RUN apt-get update && apt-get install -y \
patch \
&& rm -rf /var/lib/apt/lists/*
RUN patch nginx.tmpl letsencrypt.diff
@codekitchen
codekitchen / PuzzleGenerator.cs
Created February 13, 2017 01:06
optimized flood fill algorithm for random puzzle generation
class PuzzleGenerator {
// ... other stuff ...
class FloodFillRange {
public int startX, endX, Y;
}
// Does a flood fill of the board starting at an arbitrary floor tile,
// and then verifies that the whole board was filled.
// If not, then there's floor that isn't reachable from some other floor.
@codekitchen
codekitchen / tutorial.ipynb
Created October 19, 2016 18:52
trying out keras on the pima-indians-diabetes dataset
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.