Skip to content

Instantly share code, notes, and snippets.

@obelisk68
obelisk68 / file_transfer_for_nexus7.rb
Created Jan 10, 2019
Ruby 1.9.3 用ファイル転送プログラム
View file_transfer_for_nexus7.rb
#!/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)}
View file_transfer
#!/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 / max_heap.rb
Last active May 17, 2020
二分ヒープの Ruby 実装
View max_heap.rb
Node = Struct.new(:key, :value)
class MaxHeap
def initialize
@heap = [nil]
@size = 0
end
attr_reader :heap, :size
def insert(key, value)
@obelisk68
obelisk68 / binary_search_tree.rb
Last active Jan 5, 2019
二分探索木の Ruby 実装
View binary_search_tree.rb
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 Dec 23, 2018
Ruby で遅延評価
View le_mogumogu.rb
module Kernel
def Thunk(&bl)
a = Thunk.new
a.value = bl
a
end
def Lambda(&bl)
Lambda.new(bl)
end
@obelisk68
obelisk68 / es_sample1.rb
Last active Dec 12, 2018
ANSIエスケープシーケンスで遊ぶ
View es_sample1.rb
require_relative 'es'
L = 14 #一辺の長さ(偶数にする)
print ES.safe_scroll(L)
i = 0
x, y = ES.cursor_position
x -= 1
square = ->(width) {
@obelisk68
obelisk68 / root.rb
Last active Nov 16, 2018
平方根の計算
View root.rb
require 'prime'
module Kernel
def Root(*args)
Root.new(*args)
end
end
module ExRoot
def to_root
View thirty_one_play.go
package main
import "fmt"
import "math/rand"
import "time"
var goal = 31
func min_max(cards []int, turn bool, sum int) int {
if sum == goal { if turn {return -10} else {return 10} }
if sum > goal { if turn {return 10} else {return -10} }
@obelisk68
obelisk68 / cairo_sample1.rb
Last active Oct 19, 2018
「コマ大数学科」GIFアニメ作成
View cairo_sample1.rb
require 'cairo'
require_relative 'gifanime'
require 'matrix'
include Math
Dir.chdir("picture") #作業用ディレクトリ
Width = 300
Surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, Width, Width)
C = Cairo::Context.new(Surface)
@obelisk68
obelisk68 / rubysdl_tetris.rb
Last active Sep 29, 2018
Ruby/SDL でテトリス
View rubysdl_tetris.rb
# Gem 'rubysdl' に付属しているサンプルを modify したものです
require 'sdl'
class Object
def deep_clone
Marshal::load(Marshal.dump(self))
end
end
class Pattern