2008-07-01から1ヶ月間の記事一覧

PDF::Writer:Color::YIQ#==

require 'color' p (Color::YIQ.new() == Color::YIQ.new()) p (Color::YIQ.new() == Color::RGB.new()) で、 true true

Java FAQ:日本語コードを自動認識して読み込みたい?

Java FAQ:Q146-07「"JISAutoDetect"」の指定 public class C2008073100 { public static void main(String[] args) { byte[] sjisBytes = { (byte)0x83, (byte)0x65, (byte)0x83, (byte)0x58, (byte)0x83, (byte)0x67 }; try { String string = new String(…

ディレクティブ error

#!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : abc { print "*abc*\n"; } | def { print "*def*\n"; } | <error> abc : 'a' 'b' 'c' def : 'd' 'e' 'f' }; my $parse = new Parse::RecDescent ($grammar); while (<>) { defin</error>…

next

まんま #!/usr/bin/env lua t = { "foo", "bar", "baz" } field, value = next(t, nil) while field do print(field, "=", value) field, value = next(t, field) end で、 1 = foo 2 = bar 3 = baz

PDF::Writer:Color::YIQ.new

require 'color' p Color::YIQ.new() p Color::YIQ.new(100, 100, 100) で、 #<Color::YIQ:0x401cbb38 @q=0.0, @y=0.0, @i=0.0> #<Color::YIQ:0x40229080 @q=1.0, @y=1.0, @i=1.0></color::yiq:0x40229080></color::yiq:0x401cbb38>

Java FAQ:Shift-JIS や日本語 EUC のバイト配列から String を作るには?

Java FAQ:Q146-02 public class C2008073000 { public static void main(String[] args) { byte[] sjisBytes = { (byte)0x83, (byte)0x65, (byte)0x83, (byte)0x58, (byte)0x83, (byte)0x67 }; try { String string = new String(sjisBytes, "SJIS"); Syste…

ディレクティブ resync の値

#!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : abc { print "*abc*\n"; } | def { print "*def*\n"; } | <resync> { print "$item[0]|$item[1]\n"; } abc : 'a' 'b' 'c' def : 'd' 'e' 'f' }; my $parse = new Parse::RecDesce</resync>…

dostring, loadstring

dostring はなくなったようだ loadstring 良く分からない。eval とかではないみたい??? #!/usr/bin/env lua -- print(dostring("1+2")) -- print(loadstring("1+2")) f = loadstring("return 1+2") print(f()) で、 3

PDF::Writer:Color::YIQ.from_fraction

require 'color' p Color::YIQ.from_fraction() p Color::YIQ.from_fraction(1, 1, 1) で、 #<Color::YIQ:0x4022ab9c @q=0, @y=0, @i=0> #<Color::YIQ:0x4022906c @q=1, @y=1, @i=1>例が from_fraction でなく、new になってしまっている</color::yiq:0x4022906c></color::yiq:0x4022ab9c>

Java FAQ:文字列を Shift-JIS や日本語 EUC に変換したい

Java FAQ:Q146-01ほぼ、まんま public class C2008072900 { public static void main(String[] args) { String string = "テスト"; try { byte[] sjisBytes = string.getBytes("SJIS"); //System.out.println(sjisBytes); System.out.println(Integer.toHex…

ディレクティブ resync

#!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : abc { print "*abc*\n"; } | def { print "*def*\n"; } | <resync:[^;\n]*[;\n]> abc : 'a' 'b' 'c' def : 'd' 'e' 'f' }; my $parse = new Parse::RecDescent ($grammar); while (<>) { defin</resync:[^;\n]*[;\n]>…

dofile

#!/usr/bin/env lua if not dofile("2008072901.lua") then print("It is not possible to open the library of functions") end と print("in 2008072901.lua") で、 in 2008072901.lua It is not possible to open the library of functions?

PDF::Writer:Color::HSL#h=, #s=, #l=

require 'color' c = Color::HSL.from_fraction(0.1, 0.5, 1) p c p [c.h, c.s, c.l] c.h = 0.5 c.s = 1 c.l = 0.1 p c で、 #<Color::HSL:0x4022a840 @s=0.5, @h=0.1, @l=1> [0.1, 0.5, 1] #<Color::HSL:0x4022a840 @s=1, @h=0.5, @l=0.1></color::hsl:0x4022a840></color::hsl:0x4022a840>

Java FAQ:外部コマンドの終了コード

Java FAQ:Q103-11 public class C2008072800 { public static void main(String[] args) { try { //Process process = Runtime.getRuntime().exec("ls"); Process process = Runtime.getRuntime().exec("ls ..."); java.lang.Thread.sleep(1000); System.ou…

ディレクティブ resync とほぼ等価?な記述

#!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : abc { print "*abc*\n"; } | def { print "*def*\n"; } | /[^\n]*\n/ { $return = 0 } abc : 'a' 'b' 'c' def : 'd' 'e' 'f' }; my $parse = new Parse::RecDescent ($gr…

両方の形式を混在させたテーブルの初期化

まんま #!/usr/bin/env lua t = { 23, 45, -7; nome = "Linguagem Lua", versao = 3.0, [4]=80 } print(t[1], t[2], t[3], t['nome'], t['versao'], t[4]) で、 23 45 -7 Linguagem Lua 3 80「t = { nome = "Linguagem Lua", [1] = 3.0, [f(x)] = g(y) }」の…

PDF::Writer:Color::HSL#h, #s, #l

require 'color' c = Color::HSL.from_fraction(0.1, 0.5, 1) p c p [c.h, c.s, c.l] で、 #<Color::HSL:0x4022aa98 @s=0.5, @h=0.1, @l=1> [0.1, 0.5, 1]</color::hsl:0x4022aa98>

Java FAQ:ワイルドカードを解釈させるには?

Java FAQ:Q103-04 import java.io.*; public class C2008072700 { public static void main(String[] args) { try { String[] cmdarray = {"/bin/sh", "-c", "ls *.class"}; Process process = Runtime.getRuntime().exec(cmdarray); InputStream is = proc…

ディレクティブ resync

#!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : abc { print "*abc*\n"; } | def { print "*def*\n"; } | <resync> abc : 'a' 'b' 'c' def : 'd' 'e' 'f' }; my $parse = new Parse::RecDescent ($grammar); while (<>) { defin</resync>…

フィールドを指定したテーブルの初期化

ほぼ、まんま #!/usr/bin/env lua function f(x) return "f" end function g(x) return "g" end x = 1 y = 2 t = { name = "Language Lua", [1] = 3.0, [f(x)] = g(y) } print(t['name'], t[1], t["f"]) で、 Language Lua 3 g

PDF::Writer:Color::HSL#to_greyscale

require 'color' p Color::HSL.from_fraction.to_greyscale p Color::HSL.from_fraction(1).to_greyscale p Color::HSL.from_fraction(1, 1).to_greyscale p Color::HSL.from_fraction(1, 1, 0.5).to_greyscale p Color::HSL.from_fraction(1, 1, 1).to_grey…

Java FAQ:外部コマンドの入出力を得るには?

Java FAQ:Q103-02まんま import java.io.*; public class C2008072600 { public static void main(String[] args) { try { Process process = Runtime.getRuntime().exec("ls"); InputStream is = process.getInputStream(); BufferedReader br = new Buffe…

skipディレクティブで規則全体に直接前置子を設定する方法

#!/usr/bin/env perl use strict; use Parse::RecDescent; my $grammar = q{ inputs : <skip:','> abc { print "*abc*\n"; } | <skip:','> def { print "*def*\n"; } | ghi { print "*ghi*\n"; } abc : 'a' 'b' 'c' def : 'd' 'e' 'f' ghi : 'g' 'h' 'i' }; my $parse = new Pars</skip:','></skip:','>…

値を指定したテーブルの初期化

まんま #!/usr/bin/env lua t = {23, 45, -7, "Lua", 6+4} print(t[1], t[2], t[3], t[4], t[5]) で、 23 45 -7 Lua 101 はじまりなのか〜

PDF::Writer:Color::HSL#brightness

require 'color' p Color::HSL.from_fraction.brightness p Color::HSL.from_fraction(1).brightness p Color::HSL.from_fraction(1, 1).brightness p Color::HSL.from_fraction(1, 1, 1).brightness で、 0.0 0.0 0.0 1

Java FAQ:外部のプログラムを呼び出すには?

Java FAQ:Q103-01 public class C2008072500 { public static void main(String[] args) { try { //Runtime.getRuntime().exec("ls"); Runtime.getRuntime().exec("/bin/ls"); //Runtime.getRuntime().exec("date"); } catch (java.io.IOException e) { e.p…

skipディレクティブとコロン

ほぼ、まんま #!/usr/bin/env perl use strict; use Parse::RecDescent; $::colon = ':'; $::comma = ','; my $grammar = q{ inputs : 'a' 'b' <skip:"$::colon|$::comma"> 'c' 'd' { print "*abcd*\n"; } }; my $parse = new Parse::RecDescent ($grammar); while (<>) { defined $par</skip:"$::colon|$::comma">…

テーブルの作成

まんま #!/usr/bin/env lua t = {} print(t) t[1] = 13 t[45] = 56 print(t[1], t[45]) t["name"] = t[1] + 2 print(t["name"]) t[t] = 5 print(t[t]) t["version"] = 4 print(t["version"]) t.version = 4 print(t["version"]) t[10] = "example" t[2.34] =…

PDF::Writer:Color::HSL#to_yiq, #to_cmyk

require 'color' p [Color::HSL.from_fraction.to_yiq, Color::HSL.from_fraction.to_cmyk] p [Color::HSL.from_fraction(1).to_yiq, Color::HSL.from_fraction(1).to_cmyk] p [Color::HSL.from_fraction(1, 1).to_yiq, Color::HSL.from_fraction(1, 1).to_c…

Java FAQ:日付を決まった形式で出力

Java FAQ:Q100-06まんま import java.util.*; import java.text.*; public class C2008072400 { public static void main(String[] args) { SimpleDateFormat dateformatter = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss zzz"); String dateString = …