Fedora Core 4 下 JDK 1.5 中文設定

沒記錯的話 Fedora Core 3 時 JDK 1.5 什麼都不調,中文就有正確顯示

換了 Fedora Core 4 和 JDK 1.5.0_04 中文卻變成框框,除非用 GTK look and feel 才會正常

這裡提到的設定 可以不用 GTK L&F 也能正常顯示中文

把簡單的方法節錄一下:

1. 建立 $JAVA_HOME/jre/lib/fonts/fallback 目錄

2. 將中文字體 cp 或 ln -s 到該目錄中

Array Slice

這幾天在看 Programming Ruby (2nd. Ed.)

看到 Array 部分時,好奇試了這些個東西

a = ["a", "b", "c", "d", "e"]
a[3, -2]
a[3..1]
a[-1..1]
a[-1..-3]

結果

a[3, -2] => nil
a[3..1] => []
a[-1..1] => []
a[-1..-3] => []

我想要是我來設計,大概會給它弄成這樣

a[3, -2] => ["d", "c"]
a[3..1] => ["d", "c", "b"]
a[-1..1] => ["e", "d", "c", "b"]
a[-1..-3] => ["e", "d", "c"]

因為既然負的 index 是由最後往前數(a[-1] => “e”),我會覺得取好幾個也要有由後往前取的功能 😛


  • 留言者: T55555
  • Email:
  • 網址:
  • 日期: 2005-09-01 19:21:15

Welcome to the Ruby World.

The [] rule is also apply to []=

So, if a = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’]

and if a[3..1] => [‘d’, ‘c’, ‘b’]

What you would like to see if you write something like

a[3..1] = [1, 2, 3, 4] ?

a will become to [‘a’, 4, 3, 2, 1, ‘e’] ?

One good thing about Ruby is everything are open.

Even the core library.

There are also calibre and facets project to change the array index to the way they like.

I can easily change the length negative value behavior as you like ( the Range one, leave to yourself to do it) , for example :

class Array

alias_method :old, :"[]"

def [](*args)  # define my new [] method for Array

begin

old(*args) unless args.length == 2 && args.last < 0

(0...-args.last).inject([]) { |a, i| a << self.slice(args.first - i) }

rescue

old(*args)

end

end

end



a = %w[a b c d e] #=> a = ['a', 'b', 'c', 'd', 'e']

a[3, -2]          #=> ['d', 'c']

So, if you don’t like the default way, change to what you like.

On Ruby, you could even change 1+1 to become 3 if you like. 🙂


  • 留言者: JiaYun
  • Email:
  • 網址:
  • 日期: 2005-09-01 20:41:12

Yes, I will let a be [‘a’, 4, 3, 2, 1, ‘e’] after a[3..1] = [1, 2, 3, 4].

And I finished the homework, but only [] not []=.

class Array

alias_method :old, :"[]"

def [](*args)  # define my new [] method for Array

begin

if (args.length == 2 && args.last < 0)

(0...-args.last).inject([]) { |a, i| a << self.slice(args.first - i) }

elsif (args.length == 1 && args.first.class == Range)

range = args.first

first = range.first < 0 ? range.first + self.length : range.first

last = range.last < 0 ? range.last + self.length : range.last

if (first > last)

length = (first - last).abs

length += 1 unless range.exclude_end?

(0...length).inject([]) { |a, i| a << self.slice(range.first - i) }

else

old(*args)

end

else

old(*args)

end



rescue

old(*args)

end

end

end



a = %w[a b c d e]

a[-1..-3] #=> ["e", "d", "c"]

a[-1...-3] #=> ["e", "d"]

a[-1..1] #=> ["e", "d", "c", "b"]

a[-1...1] #=> ["e", "d", "c"]

a[4..2] #=> ["e", "d", "c"]

a[4...2] #=> ["e", "d"]


  • 留言者: T55555
  • Email: ruby55555@gmail.com
  • 網址:
  • 日期: 2005-09-02 00:09:54

Ooops, I found my bug …

The line

old(*args) unless args.length == 2 && args.last < 0

should be like

return old(*args) unless args.length == 2 && args.last < 0

Mobile Cryptography Benchmark

Mobile Phone: BenQ s680c (CLDC 1.0, MIDP 1.0)

Library: Bouncy Castle Lightweight API for J2ME (Version 1.29)

Plaintext size: 631 bytes

AES CBC mode with PKCS7 padding
plaintext blocks: 631 * 8 / 128 = 40 blocks
Unit: millisecond
Key Size Encrypt Decrypt Key Generation
AES 128 421 314 97
286 319 97
296 310 97
AES 192 449 356 143
319 346 144
328 347 148
AES 256 495 384 138
346 407 139
352 388 134
352 393 134

Comment: The first encryption is slightly slower, because there are

some classes which are first be instantiated by cipher at encryption

step, being loaded at that time.

SHA-256 & SHA-512
Unit: millisecond
SHA-256 SHA-512
847 804
860 805
874 809
856 804
851 800
Digital Signature
Unit: millisecond
Algorithm

and Key Size

Sign Verify Key

Generation

RSA 1024 142755 14389 Too

slow to run. All take more than 10 minutes on emulator running on a AMD

Athlon XP 2000+ machine. Maybe  Bouncy Castle’s

BigInteger has some problems. They are much faster with

J2SE’s BigInteger.

142117 13686
142362 14111
DSA 1024 90410 188168
92389 184935
RSA 2048 1080095 49136
1069361 49968
ECDSA prime192v1 824896 1731073
893203 1789403

Resources:

數位密碼 (Digital Fortress)

數位密碼,達文西密碼作者的第一本小說。

我沒看過達文西密碼,因為這本有談到資訊安全和密碼學的東西,又是之前又那麼紅的達文西密碼作者的書,所以好奇看看。

算是讀過一遍就罷了的書,讀起來還算有趣,情節滿曲折的,不過有些地方不是很有說服力。Amazon 上面這篇 One glaring error that ALMOST ruined it for me… 評論提到的正是我覺得最不合理的地方:(沒讀過小說可以先不要往下看)

想以動過手腳過的檔案換掉網站上原本的檔案,可是在換掉之前,原始版本早就被很多人下載了,怎麼可能保證換掉後,只有竄改過的版本會流通,原始版本從此消失,不會有人發現其中的差異。但小說裡的國安局副局長卻沒考慮到這點….

另外一點,不知道 Amazon 上有沒有評論提到,副局長既然是因為丹角和丹角捏造出來的同夥之間的 email 而相信丹角寫出了無法破解的加密法,怎麼敢那麼快派殺手殺害丹角取丹角的那份金鑰,他不怕在他來得及動手腳換檔案之前,丹角的同夥發現丹角死了而公布自己那份金鑰嗎?畢竟他一開始還不知道同夥根本不存在。

模仿癖

讀 鴛鴦神探 真覺得湯米和陶品絲有模仿癖(音痞),不時要模仿個什麼偵探,很像 Keroro 愛模仿動畫人物。

很好笑,但有時會笑到無力 (kero) 或覺得怎麼會那麼 xx (kuru),模仿成這樣。像 Keroro 用紙盒模仿福音戰士裡的 Sound Only 板子,就是會讓人想笑著罵幾句的(真是複雜的感覺 :P)。

P.S. Keroro (kero) 和 Kururu (kuru) 這兩個圖,是從 Koji 那拿到的。感謝~