Skip to content

Instantly share code, notes, and snippets.

@tompng
tompng / codeparty_trick_reline_irb.md
Last active April 18, 2025 09:20
Code Party TRICK, Reline, IRB

Code Party: IRB/Reline/TRICK

Self Introduction

These are just an idea.

Let's read TRICK codes

Let's encode and decode data in a strange way

  • Encode to a string "UnVieQ=="
@tompng
tompng / constant.rb
Last active April 24, 2025 15:34
Readable FizzBuzz
module ReadableFizzBuzz
module Chain
end
end
include ReadableFizzBuzz
Chain::Itself = Chain
module Chain::Itself
@tompng
tompng / analyzer.rb
Last active April 24, 2025 15:34
sound generation
require 'chunky_png'
require 'numo/narray'
file = ARGV[0]
data = File.binread(file)
wave = data[44..].unpack('v*').map do |v|
(v <= 0x7fff ? v : v - 0x10000).fdiv(0x8000)
end
RATE = 44100
sec = ARGV[1].to_i.nonzero? || 5
mut = Ractor.new do
pipe = Ractor.new do
loop { Ractor.yield Ractor.receive }
end
loop do
Ractor.yield pipe
pipe.take
end
end
require 'prism'
require 'ripper'
def parsey_extract_locations(code)
lines = code.lines
line_indexes = lines.reduce([0]) { _1 << _1.last + _2.bytesize }
code_index = ->(line, col) { line_indexes[line - 1] + col }
locations = []
each_node = -> node do
locs = node.locations.compact
all_tokens = %w[
x
y
false
if
rescue
begin
end
=
def
require 'irb'
require 'stringio'
def count_lines(ascii_text, width)
ascii_text.lines.sum{|l| [(l.chomp.size-1)/40+1,1].max }
end
10000.times do |i|
width = 40
height= 20
out = IRB::Pager::PageOverflowIO.new(width, height, ->*{})
require 'prism'
Dir.glob('../**/*.rb').each do |file|
next if file =~ /(^|\/)tmp\//
codes = []
prc = ->(node) {
codes << node.slice
codes << node.unescaped if node.is_a? Prism::StringNode
node.compact_child_nodes.each { prc.call it }
}
@tompng
tompng / dir_upload_client.rb
Last active December 14, 2024 05:29
simple directory uploader
require 'socket'
require 'json'
endpoint = ARGV[0]
src = ARGV[1]
dst = ARGV[2] || ''
unless endpoint =~ /\A.+:\d+\z/ && src
puts "ARGV[0]: host:port"
puts "ARGV[1]: src dir"
puts "ARGV[2]: dst dir"
puts <<RUBY.b
eval eval eval eval eval <<'CODE'
$>.set_encoding 'utf-8'
$><<"#{'あ'.b}"
<<'A'
# encoding: euc-jp
$><<"#{'い'.encode('euc-jp').b}"
<<'B'
# encoding: sjis
$><<"#{'う'.encode('sjis').b}"