Skip to content

Instantly share code, notes, and snippets.

View itarato's full-sized avatar

Peter Arato itarato

  • Montreal, Canada
  • 11:26 (UTC -03:00)
View GitHub Profile
# Terminal Tetris
#
# Usage:
#
# ```bash
# ruby tetris.rb <WIDTH> <HEIGHT> <SPEED>
# ```
#
# Control:
# - a: left
@itarato
itarato / note_to_dot.rb
Last active October 4, 2023 20:16
Notes to Dot converter
note = File.read(ARGV[0])
gid = 1
prev_indent = 0
stack = [0]
labels = ["Root"]
edges = []
note.lines.map { _1.delete!("\n") }.map do |line|
@itarato
itarato / io_reopen.md
Last active June 17, 2023 17:34
Ruby's IO#reopen - thoughts

IO#reopen and its surprising side effect

This is a short debugging story that led to a few learnings. Our team is working on making TruffleRuby support one of our larger internal Ruby application. Running tests in CI we've noticed a flaky test failure reporting:

undefined method 'write_without_cli_ui' for #<IO:<STDOUT>> (NoMethodError)

Debugging

@itarato
itarato / pipe_write_full.c
Created June 3, 2023 15:23
Demonstrating a Posix pipe writer being full and not being emptied
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#define PIPE_MAX (1 << 16)
int main() {
int pipefd[2];
@itarato
itarato / truffle_calltree_find.rb
Created April 11, 2023 14:30
Extracts a block of subtree from a callgraph of a given function (matched by a substring).
=begin
Extracts a block of subtree from a callgraph of a given function (matched by a substring).
Use:
jt ruby --cpusampler=calltree -e 'a=[];a.push(1);p(a.size)' | ruby truffle_calltree_find.rb "IO#puts"
=end
@itarato
itarato / wadis.rb
Created March 22, 2023 23:01
Redis watcher
=begin
WADIS is a Redis variable watcher.
Usage:
```shell
ruby wadis.rb <HOST> <PORT> --hkey=<key1>,<key2>... --vkey=<key1>,<key2>...
```
@itarato
itarato / thread_test_experiment.rb
Created February 19, 2023 04:28
Thread step management enhanced testing
require("thread")
class Foo
def initialize(arr)
@arr = arr
end
def update
i = @arr[-1]
@arr.push(i + 1)
@itarato
itarato / hilbert_space_filling_curve.png
Last active May 2, 2022 01:30
Turtle-ish drawing with Python
hilbert_space_filling_curve.png
@itarato
itarato / asm.hs
Last active April 25, 2022 01:50
ASM interpreter in Haskell
import Control.Monad.State
import Data.Foldable
import Text.Read
import Control.Applicative
import System.IO
data Regs = Regs {
ax::Int,
cx::Int,
dx::Int,
@itarato
itarato / data_def.rb
Last active November 5, 2020 03:35
Playing with (almost) algebraic data definitions in Ruby
class Def
class DataContainer
def initialize(name)
@name = name
@members = []
@last_constructor = nil
Object.const_set(name, self)
end