Skip to content

Instantly share code, notes, and snippets.

View ioquatix's full-sized avatar
⚖️
Let's make it scalable!

Samuel Williams ioquatix

⚖️
Let's make it scalable!
View GitHub Profile
@ioquatix
ioquatix / fibonacci.rb
Created May 17, 2020 05:04
Threads vs Processes with the GVL
# gem install async-container
gem "async-container"
require 'async/clock'
require 'async/container'
def fibonacci(n)
if n < 2
return n
require_relative 'lib/async/websocket/version'
Gem::Specification.new do |spec|
spec.name = "async-websocket"
spec.version = Async::WebSocket::VERSION
spec.authors = ["Samuel Williams"]
spec.email = ["samuel.williams@oriontransfer.co.nz"]
spec.summary = %q{An async websocket library on top of websocket-driver.}
spec.homepage = ""
@ioquatix
ioquatix / dump.rb
Created April 24, 2020 00:33
Linux Memory Dump
#!/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 = File.open("/proc/#{pid}/maps")
mem = File.open("/proc/#{pid}/mem")
@ioquatix
ioquatix / README.md
Created April 16, 2020 03:52
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
ioquatix / monads.rb
Created April 2, 2020 10:39
Compare Monads with Pure Ruby
require 'benchmark/ips'
require 'dry/monads/result'
extend Dry::Monads::Result::Mixin
def pure_square(x)
value = x ** 2
if value > 50
#!/usr/bin/env ruby
require 'async'
require 'async/http/internet'
Async do |task|
internet = Async::HTTP::Internet.new
# Effectively a connection timeout:
response = task.with_timeout(10) do
@ioquatix
ioquatix / memory.rb
Created December 29, 2019 20:52
smaps pss memory usage
#!/usr/bin/env ruby
require 'process/pipeline'
def process_group_pids(pids)
pids.flat_map do |pid|
buffer = Process::Pipeline.("pstree -p #{pid}").read
buffer.scan(/(?<=\()\d+(?=\))/)
end.sort.uniq
@ioquatix
ioquatix / async-logging.rb
Created December 28, 2019 21:38
Async nested logging
#!/usr/bin/env RBENV_VERSION=2.7.0 ruby
gem 'async'
require 'async'
Async do |task|
Async.logger.info("Incoming request...")
Async(logger: task.logger.with(name: "request-id-1234")) do
Async.logger.info("Database Query")
@ioquatix
ioquatix / fizzbuzz.s
Created December 5, 2019 14:14
Fizz Buzz X86-64 (amd64) assembly (works on Linux)
.text
.global main
main:
# Save the non-volatile registers:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
#!/usr/bin/env ruby
spread = {}
class ShiftRandom
def initialize(seed = 1)
@seed = seed
@accumulator = seed
end