Skip to content

Instantly share code, notes, and snippets.

@paddor
paddor / README Ruby snap plugin
Last active May 17, 2024 09:25
Snapcraft Ruby plugin for core20
This is one way to build a snap for a Ruby app that:
* uses Ruby 3.3 with YJIT
* uses ZMQ/CZMQ, Sqlite3, libxml2, libmbedtls, libmysqlclient
* bundles custom fonts and wktohtmlpdf for PDF generation
* has a daemon (system service) which uses the 'network-bind' plug
* respects the env vars FOOBAR_APP (path to app) and FOOBAR_CONF (path to config file)
* has a separate, bundled web UI (unpacks webui-dist.tgz to /app/webui/dist inside the snap)
* builds the snap using an LXD container
@paddor
paddor / 1brc_ractors.rb
Last active January 15, 2024 19:11 — forked from codekitchen/1brc_ractors.rb
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`,
class Base │# ./lib/roadster/messaging/protocols/csp/messages.rb:6:in `<top (required)>'
def self.property(name) │# ./lib/roadster/messaging/protocols/csp/csp.rb:6:in `require_relative'
properties << name │# ./lib/roadster/messaging/protocols/csp/csp.rb:6:in `<top (required)>'
end │# ./lib/roadster/messaging/protocols/protocols.rb:7:in `require_relative'

Keybase proof

I hereby claim:

  • I am paddor on github.
  • I am paddor (https://keybase.io/paddor) on keybase.
  • I have a public key ASB83G0OHrjTatUVY6r1RJrheLLmMgz6ezrSWDUhijVmiQo

To claim this, I am signing this object:

#! /usr/bin/env ruby
require "cztop"
require "benchmark"
if ARGV.size != 2
abort <<MSG
Usage: #{$0} <message-size> <message-count>
MSG
end
@paddor
paddor / diff.txt
Last active August 18, 2016 16:49
from Ruby to Crystal
from Ruby to Crystal:
* compiled to one binary
* (optional) type restrictions
* there's a class Bool (values are true and false)
* Nil is the type of nil (not NilClass)
* very DRY: def initialize(@name)
* nice way to avoid alias_method_chain: previous_def
* @@var is valid only in that class and its instances, not subclasses
* file-global functions can be called from within a method (foo() or explicitly ::foo())
require "benchmark"
require "uri"
HOSTS = {
"fqdn" => "example.com:3000",
"ipv6" => "[123::1]:3000",
"ipv4" => "123.123.123.123:3000",
"mapped" => "[::192.168.1.1]:3000",
"garbage" => "foo.bar:a000",
"invalid_port" => "foo:123456",
@paddor
paddor / Makefile
Created December 27, 2015 14:27
JRuby/Rubinius: doesn't abort C function when FFI::Function breaks
libcallback.dylib: callback.c
clang -dynamiclib -std=gnu99 callback.c -o $@
@paddor
paddor / Makefile
Last active December 27, 2015 09:16
Rubinius: FFI::Function doesn't return break value
libcallback.dylib: callback.c
clang -dynamiclib -std=gnu99 callback.c -o $@
@paddor
paddor / Makefile
Last active December 27, 2015 09:04
Rubinius: can't spawn a Thread from within an FFI::Function if the FFI::Function is called from another thread
libcallback.dylib: callback.h callback.c
clang -dynamiclib -std=gnu99 callback.c -o $@