Skip to content

Instantly share code, notes, and snippets.

View seki's full-sized avatar

Masatoshi SEKI seki

View GitHub Profile
@seki
seki / my_svg.rb
Last active June 9, 2024 03:58
text to svg (for debugging)
require 'erb'
class MySVG
include ERB::Util
SRC = <<EOS
<svg xmlns='http://www.w3.org/2000/svg'><%
x = 10
dy = 18
y = dy
font = 16
@seki
seki / rdv_csp.rb
Created May 12, 2024 14:46
Rdv for CSP study
require 'rinda/tuplespace'
class Rdv
def initialize(ts=nil)
@ts = ts || Rinda::TupleSpace.new
end
def select?(*chan)
template = Template.new(*chan)
t, k = @ts.take([template, nil])
@seki
seki / capture.rb
Last active November 16, 2023 07:39
capture
require 'erb'
class ERB
class ERBOut
Buffer = String # SafeBuffer if rails
def initialize(s='')
@str = Buffer.new(s)
end
@seki
seki / drb25.rhtml
Created May 23, 2023 09:18
dRuby25th logo study
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.bubble {
transition: all 0.5s;
}
</style>
@seki
seki / ndir07.rb
Last active October 11, 2022 10:38
epea ndir-07 reader
require 'serialport'
require 'json'
class EpeaNdir07
def initialize
@dev = "/dev/tty.usbserial-12210"
end
def get_ppm
sp = SerialPort.new(@dev, 115200)
@seki
seki / p5.rb
Created December 9, 2021 11:14
create 16bit PGM
name = ARGV.shift || 'p5.pgm'
buf = "P5 256 256 65535\n" + (0...(256 ** 2)).to_a.pack('n*')
File.write(name, buf)
require 'discordrb'
module Discordrb::Voice
class VoiceBot
def play_internal
count = 0
@playing = true
# Default play length (ms), will be adjusted later
@length = IDEAL_LENGTH
@seki
seki / charset.rb
Created September 12, 2021 22:03
dicom charset converter; import from js
# coding: us-ascii
module DCM_CharSet
class InvalidCharSet < RuntimeError
end
# https://github.com/cornerstonejs/dicomParser/issues/146
module_function
def parse_charset(dcm_00080005)
charset = dcm_00080005
ary = charset ? charset.strip.split('\\').map {|x| x.strip.upcase} : []
@seki
seki / dcm.rb
Last active October 28, 2021 05:55
tiny dcm
# coding: us-ascii
require 'pp'
class Dcm
module ImplicitLittle
def read_tag; read(4).unpack('vv') end
def read_vr; nil; end
def read_i2; read(2).unpack('v').first end
def read_i4; read(4).unpack('V').first end
@seki
seki / table6-1.rb
Created August 22, 2021 00:36
fetch DICOM DE
require 'nokogiri'
require 'open-uri'
fname = ARGV.shift
if fname
html = File.read(fname)
else
url = "http://dicom.nema.org/medical/dicom/current/output/chtml/part06/chapter_6.html"
html = URI.open(url).read
File.write("/tmp/chapter6.html", html)