Skip to content

Instantly share code, notes, and snippets.

Let's make it scalable!

Samuel Williams ioquatix

Let's make it scalable!
View GitHub Profile
View ipc.rb
#!/usr/bin/env ruby
require 'async'
require 'async/io/unix_endpoint'
endpoint = Async::IO::Endpoint.unix("foo.ipc")
fork do
Async do
endpoint.accept do |peer|
View searchable.rb
require 'thread/local'
class Searchable
extend Thread::Local
def initialize
@index = "rubygems"
ioquatix / query.rb
Created Jun 27, 2020
multiple queries
View query.rb
Sync do
query =<<~SQL * 10)
query.results do |result| {"#{result.count} #{result.field_names}"}
result.each do |row|, row)
ioquatix / fibonacci.rb
Created May 17, 2020
Threads vs Processes with the GVL
View fibonacci.rb
# gem install async-container
gem "async-container"
require 'async/clock'
require 'async/container'
def fibonacci(n)
if n < 2
return n
View async-websocket.gemspec
require_relative 'lib/async/websocket/version' do |spec| = "async-websocket"
spec.version = Async::WebSocket::VERSION
spec.authors = ["Samuel Williams"] = [""]
spec.summary = %q{An async websocket library on top of websocket-driver.}
spec.homepage = ""
ioquatix / dump.rb
Created Apr 24, 2020
Linux Memory Dump
View dump.rb
#!/usr/bin/env ruby
# This script reads a list of PIDs from the command line and dumps all readable memory regions.
REGION_PATTERN = /(\h+)-(\h+) (r)/
ARGV.each do |pid|
maps ="/proc/#{pid}/maps")
mem ="/proc/#{pid}/mem")
ioquatix /
Created Apr 16, 2020
How to setup v4l2 loopback for use with OBS.

Firstly, you need to install v4l2loopback and obs-v4l2sink. On arch linux with yay:

yay -Syu obs-v4l2sink v4l2loopback-dkms

Then, set up a systemd service:

koyoko% cat /etc/systemd/system/v4l2loopback.service 
ioquatix / monads.rb
Created Apr 2, 2020
Compare Monads with Pure Ruby
View monads.rb
require 'benchmark/ips'
require 'dry/monads/result'
extend Dry::Monads::Result::Mixin
def pure_square(x)
value = x ** 2
if value > 50
View request_with_timeouts.rb
#!/usr/bin/env ruby
require 'async'
require 'async/http/internet'
Async do |task|
internet =
# Effectively a connection timeout:
response = task.with_timeout(10) do
ioquatix / memory.rb
Created Dec 29, 2019
smaps pss memory usage
View memory.rb
#!/usr/bin/env ruby
require 'process/pipeline'
def process_group_pids(pids)
pids.flat_map do |pid|
buffer = Process::Pipeline.("pstree -p #{pid}").read
You can’t perform that action at this time.