Skip to content

Instantly share code, notes, and snippets.

@obelisk68
obelisk68 / file_search
Last active December 29, 2019 14:21
findコマンドのGUI化
@obelisk68
obelisk68 / gray_scott_gtk.rb
Last active November 14, 2019 16:31
Gray_Scott を Gtk でアニメーション表示
require 'numo/narray'
require 'gtk3'
include Numo
SPACE_GRID_SIZE = 256
VISUALIZATION_STEP = 8
Dx = 0.01
Du = 2e-5
Dv = 1e-5
@obelisk68
obelisk68 / turtle_knuth_curve.rb
Created February 6, 2018 03:32
クヌース曲線
require 'oekaki'
require_relative 'turtle'
Width, Height = 600, 350
Oekaki.app width: Width, height: Height, title: "Knuth curve" do
draw do
clear
t = Turtle.new(Width, Height, self)
@obelisk68
obelisk68 / operations_parser.rb
Last active May 27, 2019 09:30
四則演算のパーサー(Ruby)
def parse(text)
splited = text.scan(/[0-9\.]+|\+|\-|\*|\/|\(|\)|=/)
output = []
stack = []
a = nil
until (token = splited.shift) == "="
case token
when "(" then stack << token
when ")"
@obelisk68
obelisk68 / blackjack.rb
Last active March 17, 2019 12:46
カードゲーム「ブラックジャック」の実装
deck = nil #カードの山
shuffle = lambda do
print "カードをシャッフルします\n\n"
deck = 4.times.flat_map {|i| (1..13).map {|j| i * 100 + j} }.shuffle
end
# 一回の勝負
@obelisk68
obelisk68 / simulated_annealing.rb
Created February 14, 2019 14:18
「最短ヌクレオチド連鎖問題」焼きなまし法
def dist(a, b)
case
when a[1, 2] == b[0, 2] then 1
when a[-1] == b[0] then 2
else 3
end
end
L = 64
start_t = 171
@obelisk68
obelisk68 / file_transfer_for_nexus7.rb
Created January 10, 2019 12:35
Ruby 1.9.3 用ファイル転送プログラム
#!/usr/bin/env ruby
# encoding : utf-8
require 'socket'
require 'thwait'
def file_send
host = ARGV[0]
q = Queue.new
30.times {q.push(:unlock)}
#!/usr/bin/env ruby
require 'socket'
require 'thwait'
def file_send
host = ARGV[0]
q = Queue.new
30.times {q.push(:unlock)}
send_file = ->(name) {
@obelisk68
obelisk68 / binary_search_tree.rb
Last active January 5, 2019 07:53
二分探索木の Ruby 実装
class Node < Struct.new(:key, :value, :left, :right)
def inspect
l, r = "", ""
l = ", @left='#{left}'" if left
r = ", @right='#{right}'" if right
"#<Node:@key='#{key}', @value='#{value}'#{l}#{r}>"
end
alias :to_s :inspect
end
@obelisk68
obelisk68 / le_mogumogu.rb
Last active December 23, 2018 00:20
Ruby で遅延評価
module Kernel
def Thunk(&bl)
a = Thunk.new
a.value = bl
a
end
def Lambda(&bl)
Lambda.new(bl)
end