Skip to content

Instantly share code, notes, and snippets.

View araipiyo's full-sized avatar
🌴
Always on vacation:)

Shunichi Arai araipiyo

🌴
Always on vacation:)
View GitHub Profile
@araipiyo
araipiyo / mp4parse.rb
Created May 17, 2023 18:41
Rubyでmp4コンテナを表面的にパースするだけのコード
def atom(file, indent = 0)
return nil if file.eof?
headersize = 8
size = file.read(4).unpack('N')[0]
type = file.read(4)
if size == 1
size = file.read(8).unpack('Q>')[0]
headersize += 8
elsif size == 0
@araipiyo
araipiyo / covid19.py
Created March 14, 2020 02:25 — forked from skoba/covid19.py
COVID-19 simuation by SEIR model
# The preprints is available from https://www.preprints.org/manuscript/202002.0179/v1
# S Susceptible
# E Exposed
# I Infected
# R Recovery
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
r0 = 3. # basic reproduction number
def trim(v)
v & 0xffffffff
end
def scramble(v)
v ^= 0x1ca7bc5b
v *= 0x1ca7bc5b
v = trim(v)
v = ((v >> 1) & 0x55555555) | trim((v & 0x55555555) << 1)
@araipiyo
araipiyo / maybe.rb
Created June 14, 2014 08:14
maybe for Ruby. easier handling of nil. nil is most bothersome thing in Ruby, right?
require 'singleton'
class Object
def maybe
if self.class == NilClass
Maybe.instance
else
self
end
end
@araipiyo
araipiyo / mockmail.rb
Created June 1, 2014 15:07
Simpliest mock SMTP server
require 'socket'
require 'nkf'
DEBUG = false
#KANJI = nil
KANJI = '-s'
def data(sock)
s = ""
@araipiyo
araipiyo / speed.rb
Created June 1, 2014 06:27
measure speed of HTTP GET at any particular site.
require 'net/http'
require 'uri'
url = URI.parse(ARGV[0])
http = Net::HTTP.new(url.host, url.port)
path = url.path != '' ? url.path : '/'
path += url.query ? "?#{url.query}" : ""
secs = []