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
$ gem-codesearch "fptr->fd" | egrep -v "tauplatform|mruby-io|ruby/io.c|ruby/file.c|ruby/ext|rubylib/file.c|ossl_ssl\.c"
2015-05-30 /srv/gems/aarontc-serialport-1.4.0/ext/native/posix_serialport_impl.c: return (fptr->fd);
2015-05-30 /srv/gems/aarontc-serialport-1.4.0/ext/native/win_serialport_impl.c: return (HANDLE) _get_osfhandle(fptr->fd);
2017-01-10 /srv/gems/abaci-0.3.0/vendor/bundle/gems/nio4r-1.2.1/ext/nio4r/nio4r.h:# define FPTR_TO_FD(fptr) fptr->fd
2010-10-28 /srv/gems/amardaxini-ruby-gd-0.8.0/GD.c: #define FILE_POINTER_FOR_CREATE_FROM fdopen(fptr->fd, "r")
2020-03-09 /srv/gems/argon-1.3.1/vendor/bundle/ruby/2.7.0/gems/nio4r-2.5.2/ext/nio4r/nio4r.h:# define FPTR_TO_FD(fptr) fptr->fd
2009-08-28 /srv/gems/arika-ruby-termios-0.9.6/termios.c:#define FILENO(fptr) (fptr->fd)
2010-04-16 /srv/gems/astro-em-http-request-0.2.10/ext/buffer/em_buffer.c:#define FPTR_TO_FD(fptr) (fptr->fd)
2017-01-26 /srv/gems/autocompl-0.2.2/test/dummy/vendor/bundle/ruby/2.3.0/gems/nio4r-1.2.1/ext/nio4r/nio4r.h:# define
@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 / stress.rb
Created June 3, 2022 06:42
Small stress test of async-http server (unimportant), client and barrier with timeout.
#!/usr/bin/env ruby
require 'async/container'
require 'async/barrier'
require 'async/http'
require 'async/io/shared_endpoint'
Console.logger.debug!
endpoint = Async::HTTP::Endpoint.parse('http://127.0.0.1:9294')
@ioquatix
ioquatix / benchmark.swift
Created June 2, 2022 11:19
UIImage Performance
extension DispatchTimeInterval {
func toDouble() -> Double? {
var result: Double? = 0
switch self {
case .seconds(let value):
result = Double(value)
case .milliseconds(let value):
result = Double(value)*0.001
case .microseconds(let value):
@ioquatix
ioquatix / async-slack.rb
Last active April 16, 2022 22:28
Make slack-api great again
# This is used in production, but I've extracted everything here, so this particular code is untested, but should work.
gem 'async-http-faraday'
gem 'async-websocket'
gem 'slack-api'
require 'slack'
require 'async/http/url_endpoint'
#!/usr/bin/env ruby
require 'benchmark'
class Reading
def initialize
@r, @w = IO.pipe
@thread = Thread.new do
@r.read
@ioquatix
ioquatix / reflector.conf
Last active February 14, 2021 05:07
Reflector weekly update for fast arch linux package download in New Zealand!
samuel@hana ~ [1]> sudo systemctl enable --now reflector.timer
Created symlink /etc/systemd/system/timers.target.wants/reflector.timer → /usr/lib/systemd/system/reflector.timer.
samuel@hana ~> cat /etc/xdg/reflector/reflector.conf
# Reflector configuration file for the systemd service.
#
# Empty lines and lines beginning with "#" are ignored. All other lines should
# contain valid reflector command-line arguments. The lines are parsed with
# Python's shlex modules so standard shell syntax should work. All arguments are
# collected into a single argument list.
#!/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|
require 'thread/local'
class Searchable
extend Thread::Local
def initialize
@index = "rubygems"
end