Skip to content

Instantly share code, notes, and snippets.

@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)
@seki
seki / co2.ino
Created April 11, 2020 16:31
M5Stack + MH-Z14 CO2 censor
#include <M5Stack.h>
#define NBIN 30
static int16_t s_ring[NBIN];
static int s_curr;
static int16_t s_bg;
static int s_delay = 20000;
static unsigned long s_tm;
void setup() {
require 'rubyXL'
require 'rubyXL/convenience_methods'
workbook = RubyXL::Parser.parse('201909.xlsx')
puts workbook[0].sheet_name
row = 4
while x = workbook[0][row][3].value
puts x
row += 2
end
@seki
seki / forktest.rb
Last active October 14, 2019 10:31
close on fork
require 'drb'
def test_fd
sleeper = DRbObject.new_with_uri('druby://localhost:50097')
ary = 20.times.collect {
Thread.new { sleeper.sleep(5) }
}
ary.each {|th| th.join}
@seki
seki / grip.rb
Created July 7, 2019 09:15
a simple kvs using git (rugged)
require 'rugged'
require 'cgi'
class Grip
def initialize(dir)
@dir = dir
@git = Rugged::Repository.new(@dir) rescue git_init
@author = {email: '[email protected]', name: 'seki'}
@message = 'via grip'
end
require 'thread'
class Crawler
def initialize(root='.', pattern='**/*.rb', period=5)
@root = File.expand_path(root)
@pattern = pattern
@period = period
@last = {}
@queue = SizedQueue.new(2)
end
@seki
seki / sqlite3-util.rb
Created August 27, 2018 12:22
sqlite3-util.rb
class SQLite3::Database
def statement(s)
if @cache.nil?
@cache = Hash.new { |h, k| h[k] = self.prepare(k) }
end
@cache[s]
end
end
class SQLite3::Statement
@seki
seki / fact.rb
Created May 27, 2018 16:27
MinRuby with Rinda
write("fact", 1, 1)
n = 2
while n <= 10
eval("fact", n, take("fact", n - 1, nil)[2] * n)
n = n + 1
end
p take("fact", 10, nil)
@seki
seki / root.rb
Last active April 30, 2018 16:56
minruby + STM
require 'my_drip'
MyDrip.invoke
def root
Root.new
end
class Root
class VersionMismatchError < RuntimeError; end