2009-06-01から1ヶ月間の記事一覧

ParallelFor

出来ましたよと. ブロック内の計算量が少ない場合、ループの中で関数コールするオーバーヘッドが大きくなるので、2引数の無名関数にも対応. unit ParallelUtils; interface uses Windows, SysUtils, Forms; procedure ParallelFor(Start, Stop: Integer; Blo…

OpenMP テスト

MinGW GCC 4.4.0 リリース記念、OpenMP 動作テスト. テスト後に libgomp-1.dll が GPL であることに気づき絶望した. pthreadGC2.dll は LGPL なのに・・・. #include <stdio.h> #include <omp.h> int main() { int i; #pragma omp parallel for for(i = 0; i < 20; i++) { pr</omp.h></stdio.h>…

RGB to L*a*b*

Delphi に移植しないと・・・. def xyz2rgb(xyz): def from_linear(v): def clamp(v): if v < 0.0: return 0.0 elif v > 1.0: return 1.0 else: return v if v <= 0.0031308: return int(clamp(v * 12.92) * 255.0 + 0.5) else: return int(clamp(1.055 * v …

PDF を暗号化する

Jython で PDF を暗号化するスクリプト. Jython 2.5.0 + iText 2.1.5 + Bouncy Castle 1.43 で動作確認. Jython 2.5.0 リリース記念(嘘). Office 2007 SP2 リリース記念(本当). from sys import argv from java.io import FileOutputStream from com.lowagie…

mod_rewrite で Content-Encoding: gzip

CentOS 5.3 (httpd-2.2.3-22.el5.centos.1) 及び さくらのレンタルサーバ(Apache/1.3.41) で動作確認済. 直接 .gz に来られた時に、Accept-Encoding に関わらず Content-Encoding: gzip になるのがイケてないけど気にしない :-D. <IfModule mod_rewrite.c> RewriteEngine On RewriteB</ifmodule>…

subjectAltName

複数の FQDN に対して有効な証明書を作ってみるテスト. 具体的には x509v3 拡張の subjectAltName を使う. やり方としては CSR に subjectAltName を入れて、署名時にそれをコピー. 署名時に subjectAltName を入れる の2パターンがある. 今回は前者で作成. …

gzip_decode

なんとなく書いてしまったので. def gzip_decode(data): from zlib import decompress, MAX_WBITS def skip_string(data, i): while data[i] != '\0': i += 1 return i + 1 flag = ord(data[3]) i = 10 if flag & 0x04: i += 2 + ord(data[i]) + 256 * ord(d…

GetNumberOfProcessors

そろそろ並列プログラミングの世界へってことで準備体操. function GetNumberOfProcessors(): Integer; var SystemInfo: TSystemInfo; begin GetSystemInfo(SystemInfo); Result := SystemInfo.dwNumberOfProcessors; end;

prettifyjson.py

json.dump が ASCII 範囲外を勝手にエスケープするのはどうかと思います. 入力 stdin, 出力 stdout、文字エンコーディングは入出力ともに UTF-8 を想定. #!/usr/bin/env python from json import load, dumps from sys import stdin, stdout stdout.write(du…

Apache のアクセスログを TSV に変換する

setbuf 重要. stdout に fflush するのは初めてだw #include <stdio.h> int main() { int c; int q = 0; int b = 0; char buf[BUFSIZ]; setbuf(stdout, buf); while ((c = getchar()) != EOF) { switch (c) { case ' ': case '[': case ']': case '"': if ((c == ' ')</stdio.h>…