この広告は、90日以上更新していないブログに表示しています。
" Hello, world!".strip#=> "Hello, world!"
>>" Hello, world!".strip=>"Hello, world!">>"\t\t\tHello, world!\n\n\n".strip=>"Hello, world!">> s =" Hello, world!"=>" Hello, world!">> s=>" Hello, world!">> s.strip=>"Hello, world!">> s=>" Hello, world!"# String#strip は非破壊的>> s.strip!=>"Hello, world!">> s=>"Hello, world!"# String#strip! は破壊的
h =Hash.newifnot h[:key] h[:key] =0endh[:key] +=123
h =Hash.newifnot h.key?:key h[:key] =0endh[:key] +=123
h =Hash.new(0)h[:key] +=123
h =Hash.new([])h[:key] <<:value
h =Hash.new(0)h[:key] |=0b1011
# makepass.rbrequire'io/console'require'digest/sha2'require'base64'require'win32/clipboard'Win32::Clipboard.set_data('')STDIN.noechodo |io| puts"Hit many keys randomly." s = io.getswhile s.length <100 puts"I need more random keys." s += io.getsend d =Digest::SHA512.digest(s) e =Base64.encode64(d) e.gsub!(/[\+\/=\n]/,'') puts"Thanks. I've saved a password-like string in your clipboard."Win32::Clipboard.set_data(e)end
C:\> ruby -vruby 1.9.3p374 (2013-01-15) [i386-mingw32]C:\> gem install win32-clipboardFetching: win32-api-1.4.8-x86-mingw32.gem (100%)Fetching: windows-api-0.4.2.gem (100%)Fetching: windows-pr-1.2.2.gem (100%)Fetching: win32-clipboard-0.5.2.gem (100%)Successfully installed win32-api-1.4.8-x86-mingw32Successfully installed windows-api-0.4.2Successfully installed windows-pr-1.2.2Successfully installed win32-clipboard-0.5.24 gems installedInstalling ri documentation for win32-api-1.4.8-x86-mingw32...Installing ri documentation for windows-api-0.4.2...Installing ri documentation for windows-pr-1.2.2...Installing ri documentation for win32-clipboard-0.5.2...Installing RDoc documentation for win32-api-1.4.8-x86-mingw32...Installing RDoc documentation for windows-api-0.4.2...Installing RDoc documentation for windows-pr-1.2.2...Installing RDoc documentation for win32-clipboard-0.5.2...C:\> ruby makepass.rbHit many keys randomly. ←ここでキーボードを乱打し、最後にENTERキーを打つ。I need more random keys. ←キー不足のときにはこういう表示になる。Thanks. I've saved a password-like string in your clipboard.この時点でクリップボードに、4GXt2VP9lpievshQmAVYFOJtXqQ26YadHFei1HYRyYTnNH8EPvIETEg6rjTr6DssOrPSArECcCCqrqfBsqAのようなパスワードっぽい文字列が入っているので適当に使う。
最近Rubyをアップデートしてなかったので、この機会に1.9へ。
C:\>ruby -vruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]
C:\>ruby -vruby 1.9.3p125 (2012-02-16) [i386-mswin32_100]
はい、できました。
結城浩(id:hyuki)さんが『数学ガール/ガロア理論』をLaTeXで書いているときに使っていたRubyスクリプトです。
Windowsで動作することを仮定しています。
やっていることは、
というものです。ほとんどバッチファイル代わりですね。
Acrobatが共有禁止で握っているPDFに上書きするために、途中でAcrobat.exeを殺しています。乱暴な…。
require"fileutils"PLATEX_OPTION =''TMP_DIR ='\\tmp'DROPBOX_DIR ='C:\\My Dropbox'PDF_NUMBER ='5'ifARGV.length ==0abort"Usage: texpdf.rb filename[.tex] [a5|a4] [once|twice]"endfrom =ARGV[0].gsub(/\.tex$/,"")ifARGV.length >=2ifARGV[1] =='a5' ||ARGV[1] =='a4' page_size =ARGV[1]else page_size ='a4'endendifARGV.length >=3ifARGV[2] =='once'MAKE_INDEX =falseelseMAKE_INDEX =trueendendtime =Time.now.strftime("%Y-%m-%d-%H%M%S")to_dir ="#{TMP_DIR}\\_#{time}"texname ="#{from}.tex"dvifile ="#{from}.dvi"pdffile ="#{from}.pdf"system("mkdir#{to_dir}")system("xcopy /Y /s *.*#{to_dir}")Dir.chdir("#{to_dir}")puts"Create#{dvifile}."system("platex#{PLATEX_OPTION}#{texname}")abort"pLaTeX error."unless$? ==0puts"Kill Acrobat."system("taskkill /IM Acrobat.exe")ifMAKE_INDEX puts"Make index." system("makeindex#{from}") system("mendex#{from}") system("platex#{PLATEX_OPTION}#{texname}")abort"pLaTeX error."unless$? ==0endabort"#{dvifile} is not found."unlessFile.exist?(dvifile)puts"Create#{pdffile}."system("dvipdfmx -d#{PDF_NUMBER} -p#{page_size}#{dvifile}")abort"#{pdffile} is not found."unlessFile.exist?(pdffile)puts"Copy to dropbox."system("xcopy /Y#{pdffile} \"#{DROPBOX_DIR}\"")puts"Show#{pdffile}."system("start#{pdffile}")
祝! 軽量Rubyが公開を参考にさせていただいて、Windows XPでmrubyをビルドして動かしてみました。
$ ls binmrbc.exe mruby.exe mrubysample.exe
$ cat hello.rbprint "Hello!\n"
$ ./bin/mruby hello.rbHello!
(ご指摘を受けて、s/mRuby/mruby/しました)
すでにGitがインストールされているとして。
C:\> mkdir mrubyC:\> cd mrubyC:\mruby> git clone https://github.com/mruby/mruby.gitCloning into mruby...remote: Counting objects: 462, done.remote: Compressing objects: 100% (247/247), done.remote: Total 462 (delta 222), reused 448 (delta 211)Receiving objects: 100% (462/462), 560.79 KiB | 229 KiB/s, done.Resolving deltas: 100% (222/222), done.C:\mruby> cd mruby
あとは好きに眺める。
(るびこさんのエントリを書くのは久しぶりですね)
引用をストックしました
引用するにはまずログインしてください
引用をストックできませんでした。再度お試しください
限定公開記事のため引用できません。