This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def *(arr) | |
self.each_with_index.map{|e,i| e*arr[i] } | |
end | |
end | |
[3,4,5] * [6,-7,8] #=> [18,-28,40] | |
[[1,2],[3,4]] * [[-2,-3],[-3,-4]] #=> [[-2, -6], [-9, -16]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Encoding.default_external = "utf-8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
net localgroup TelnetClients <username> /add |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
telnet = Net::Telnet.new("Host" => "localhost","Prompt" => /[$%#>]\z/n,"Output_log" => "Output_log.txt") {|c| print c} | |
#Promptはデフォルトを使わない | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem install openwferu-scheduler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!ruby | |
# coding: utf-8 | |
require 'openwfe/util/scheduler' | |
include OpenWFE | |
#schedulerインスタンスを作成しスタートさせる | |
scheduler = Scheduler.new | |
scheduler.start | |
# Cronでの記述ができる | |
# 毎分に実行する例 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
#まずクラス定義 | |
class MyClass | |
def hook | |
square(3) | |
end | |
def square(n) | |
n * n | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def commit(symbol,*arg) | |
c = 0 | |
begin | |
return self.send(symbol.to_sym,*arg) | |
rescue | |
c += 1 | |
retry if c < 5 | |
end | |
"get less than 90 5 times..." | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def time_watch(&b) | |
t1 = Time.now | |
yield | |
t2 = Time.now | |
t2-t1 | |
end | |
time_watch{sleep 4} | |
#=> 4.000228 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# usage: | |
# ruby worker-daemonize start | |
# | |
require 'daemon_spawn' | |
require File.expand_path('../job',__FILE__) | |
WorkingDir = File.expand_path('../wd',__FILE__) | |
class ResqueWorkerDaemon < DaemonSpawn::Base |
OlderNewer