Skip to content

Instantly share code, notes, and snippets.

View myokoym's full-sized avatar
💭
hi

Masafumi Yokoyama myokoym

💭
hi
View GitHub Profile
@myokoym
myokoym / keyboard.rb
Created November 2, 2010 13:41
Mouse で keyboard 入力.
#!ruby -Ks
require 'vr/vruby'
require 'vr/vrcontrol'
require 'win32/clipboard'
class Frm_form1 < VRForm
@caps_flag = false
def _form1_init
@myokoym
myokoym / gist:1104078
Created July 25, 2011 13:08
0〜9までの数値を重複しないように4つ並べた配列を取得する
# [0-9]{4} (unique)
Array.new(10) {|i| i }.shuffle.slice(0, 4)
@myokoym
myokoym / asx_to_mms.rb
Created September 7, 2011 15:37
とあるファイルからとある部分を取り出すスクリプト
#!ruby
mms_list = []
Dir.glob("*.asx") do |fn|
File.open(fn) {|f|
mms_list << f.read.scan(/(mms:.*?)"/)
}
end
File.open("mms_list.txt", "a") {|f|
@myokoym
myokoym / convmv_euc_to_sjis.pl
Created July 11, 2012 13:54
全角ファイル名の文字コードを再帰的に変換するスクリプト(convmvがインストールできない環境のため自作)
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
use File::Copy;
use Encode;
my $target_dir = $ARGV[0];
my $option = $ARGV[1];
@myokoym
myokoym / fujiiget.rb
Created August 2, 2012 14:48
藤井がんがれ
#!ruby
require 'open-uri'
loop do
outfile = "C:/data/fujii_#{Time.now.strftime('%Y%m%d%H%M%S')}.jpg"
open(outfile, "wb") do |output|
open("http://live10.shogi.or.jp/oui/camera/3/fujii.jpg") do |data|
output.write(data.read)
puts outfile
@myokoym
myokoym / gist:3237623
Created August 2, 2012 14:55
ファイルリネーム用ワンライナー
ruby -r fileutils -e "Dir.glob('*').each_with_index {|fn, i| FileUtils.mv fn, fn.sub(/置換前/, \"置換後\") }"
@myokoym
myokoym / gist:3360286
Created August 15, 2012 13:43
ある金額になる硬貨の組み合わせを求めるメソッド
#! ruby
# coins.sort.reverse!
def calc(sum, coins)
if coins.size == 1
return (sum % coins[0] == 0) ? 1 : 0
end
count = 0
num = coins[0]
@myokoym
myokoym / gist:3360724
Created August 15, 2012 14:44
ある金額になる硬貨の組み合わせを求める(邪悪流)
#! ruby
sum = 30
coins = [10, 5, 1]
coins.sort.reverse!
count = 0
1.upto(sum) do |n|
count += coins.repeated_combination(n).count {|a| a.inject(:+) == sum }
@myokoym
myokoym / p032.rb
Created August 15, 2012 15:19
1~9までの数値を云々するスクリプト(Problem032)
#! ruby
digits = 9
ans = []
(1..digits).to_a.permutation(digits) do |a|
0.upto(digits - 3) do |i|
i.upto(digits - 3) do |j|
x = a[0..i].join.to_i
y = a[(i + 1)..(j + 1)].join.to_i
@myokoym
myokoym / problem033.rb
Created August 16, 2012 13:20
Problem033
#! ruby
buns = []
10.upto(99) do |i|
i.upto(99) do |j|
buns << [i, j]
end
end
results = []