6. Scripting Language The origin of the term was similar to its meaning in "a movie script tells actors what to do": a scripting language controlled the operation of a normally-interactive program, giving it a sequence of work to do all in one batch. For instance, one could put a series of editing commands in a file, and tell an editor to run that "script" as if those commands had been typed interactively. http://www.c2.com/cgi/wiki?ScriptingLanguage
13. I ROBOT 2009/200902.tdcをエディタで開く TDIARY2.00.00 Date: 20090204 Name: メル Mail: Last-Modified: 1139188007 Visible: true こないだ私のお兄さんとしたんですけど、不幸なことが . Date: 20090204 Name: paealos Mail: Last-Modified: 1140972441 Visible: true Viagra are often the first treatment tried for erectile . Date: 20090204 Name: アリバイ会社 Mail: Last-Modified: 1140972441 Visible: true <a href="http://dmajor.info/>アリバイ会社</a> . sudo –u www-data vi … 削除
14. http://tach.arege.net/trac/browser/tdiary/trunk/contrib/util/clean-spam?rev=713 #!/usr/bin/env ruby # # Copyright (C) 2004 Satoru Takabayashi <satoru@namazu.org> # You can redistribute it and/or modify it under GPL2. # puts "Usage: tdiary-comment-clean PATTERN FILE..." if ARGV.length == 0 pattern = Regexp.new(ARGV.shift) file_names = ARGV deleted_comments = [] file_names.each {|file_name| i = File.open(file_name) first_line = i.gets (continue…)
15. file_names.each {|file_name| i = File.open(file_name) first_line = i.gets comments = [] comment = "" while line = i.gets if line == "." comments.push(comment) comment = "" else comment << line end end i.close (continue…)
20. @echo off c:rogra~1uby-1.9srinuby -x /Users/arton/bin/sha256sum.bat %* @gotoendofruby #!/usr/bin/ruby require 'digest/sha2' def sha256sum(str) sha256 = Digest::SHA2.new sha256.update(str) sha256.hexdigest end def file(name) File.open(name, 'rb') do |f| yield sha256sum(f.read) end end if ARGV.length == 0 STDERR.puts( 'usage: ruby sha256sum.rb file [more file...]‘) else ARGV.each do |a| file(a) do |sum| puts "#{sum} #{a}" end end end __END__ :endofruby
22. 余談:巨大なファイル def file(name) File.open(name, 'rb') do |f| buff = 'x' * 16384 sha256 = Digest::SHA2.new while len = f.read(buff.size, buff) sha256 << buff 自動伸縮 end yield sha256.hexdigest end end
23. 余談:速度比較(470MBファイル) (一括読み込み版) c:omertonuby>sha256sum “Windows Mobile 6 Professional SDK Refresh.msi" ff2bccc6d9618ff64d8172e9612f7fc46342f9e055bf99b407e689b74fad321b Windows Mobile 6 Professional SDK Refresh.msi 16.723000 1.092000 17.815000 ( 22.539000) (16KB分割読み込み版) c:omertonuby>sha256sum “Windows Mobile 6 Professional SDK Refresh.msi" ff2bccc6d9618ff64d8172e9612f7fc46342f9e055bf99b407e689b74fad321b Windows Mobile 6 Professional SDK Refresh.msi 17.020000 0.905000 17.925000 ( 17.749000) c:omertonuby> いい時代だ……
30. 自前start-stop-daemon if ARGV[0] == ‘stop' if File.exist?(PIDFILE) File.open(PIDFILE, 'r') do |f| pid = f.read end begin Process.kill(-9, pid.to_i) rescue end File.delete(PIDFILE) end elsif ARGV[0] == ‘start' init_policy pid = fork if pid.nil? Process.setpgrp() exec(CMD) else File.open(PIDFILE, 'w') do |f| f.write(pid.to_s) end end end