Skip to content

Instantly share code, notes, and snippets.

@obelisk68
obelisk68 / upload_to_gist.rb
Last active May 2, 2017 08:00
Created by RubyPico at Tue May 02 16:59:50 2017
def main
fname = Popup.input("ファイル名を入力して下さい")
return unless fname
unless File.exist?(fname) and File.file?(fname)
puts "ファイルが存在しないか、ディレクトリです"
return
end
file_content = File.open(fname) {|io| io.read}
@obelisk68
obelisk68 / github_rubypico_update.rb
Last active May 2, 2017 08:22
Created by RubyPico at Tue May 02 17:21:13 2017
def bget(url, token)
if token
ret = Browser.get(url, header: { "Authorization" => "token #{token}"})
else
ret = Browser.get(url)
end
JSON::parse(ret)
end
@obelisk68
obelisk68 / f_delete.rb
Created May 2, 2017 08:52
Created by RubyPico at Tue May 02 17:52:20 2017
def main
fname = Popup.input("削除するファイル名かフォルダ名")
if not File.exist?(fname)
puts "ファイルまたはフォルダが存在していません"
return
elsif File.file?(fname)
File.delete(fname)
else
Dir.rmdir(fname)
@obelisk68
obelisk68 / class_reference.rb
Created May 2, 2017 11:17
Created by RubyPico at Tue May 02 20:17:08 2017
def main
loop do
name = choise(class_list, combine: true)
clear
puts Module.const_get(name).info
puts
choise(["戻る"])
clear
N = 8
class EightQueen
class Step
def initialize(x, y)
@x, @y = x, y
@parent = nil
@depth = 0
end
attr_accessor :x, :y, :parent, :depth
@obelisk68
obelisk68 / bad_code.c
Last active August 24, 2017 12:44
関数内で宣言した配列変数をreturnしてはいけない
#include <stdio.h>
char *keyboard_linein() {
char buf[1000];
fgets(buf, 1000, stdin);
printf("%s\n", buf);
return buf;
}
@obelisk68
obelisk68 / oekaki_sample12.rb
Last active August 30, 2017 05:53
円が降ってくる(スクリーンセーバーもどき)
require 'oekaki'
Width, Height = if ARGV.size == 2
ARGV.map(&:to_i)
else
[1000, 700]
end
Max_r, Min_r = 40, 10
ColorMax = 65535
@obelisk68
obelisk68 / miniopengl_sample6.rb
Last active September 6, 2017 05:12
OpenGL で正多面体を回転させる
require './miniopengl'
require 'parallel'
filenames = []
1.upto(5) {|i| filenames << "./polyhedrons_obj/r" + ("%02d" % i) + ".obj"}
data = []
filenames.each do |fn|
open(fn, "r") do |io|
ar = [[], []]
@obelisk68
obelisk68 / oekaki_sample14.rb
Last active September 8, 2017 08:47
移動する内接円
require 'oekaki'
Width, Height = 400, 300
CircumcircleR = 0.8
def incircle(a, b, c)
l, m, n = (b - a).norm, (c - b).norm, (a - c).norm
q = l + m + n
po = a * (m / q) + b * (n / q) + c * (l / q)
@obelisk68
obelisk68 / poh2.rb
Last active October 18, 2017 03:31
paiza オンラインハッカソン vol.2 の解説アルゴリズムで
height, width = gets.split.map(&:to_i)
window = []
height.times {window << gets.chomp.chars.map(&:to_i)}
num = gets.to_i
wgtsize = []
num.times {wgtsize << gets.split.map(&:to_i)}
height.times do |h|
(width - 1).times {|w| window[h][w + 1] += window[h][w]}
end