via http://d.hatena.ne.jp/sugyan/20101003/1286035489
おぉ。こんなことできるのね。Ubuntuの場合は apt で libgtk2-notify-perlをインストールすれば
Log::Dispatch::DesktopNotification のバックエンドとして Log::Dispatch::Gtk2::Notify が動く。(正確にはさらに Gtk2::Notify が呼ばれているみたい)

via http://d.hatena.ne.jp/sugyan/20101003/1286035489
おぉ。こんなことできるのね。Ubuntuの場合は apt で libgtk2-notify-perlをインストールすれば
Log::Dispatch::DesktopNotification のバックエンドとして Log::Dispatch::Gtk2::Notify が動く。(正確にはさらに Gtk2::Notify が呼ばれているみたい)

初めてのPHP & MySQL 第2版 を読んだ自分用メモ。PHP の部分はスルー。途中から抜けが多いけど本にはしっかり書いてあるよ!
mysql -h host -u user -p
SHOW DATABASES;
USE mysql;
GRANT ALL PRIVILEGES ON *.* TO 'user'@'hostname' IDENTIFIED BY 'password'
CREATE DATABASE store; USE store;
CREATE TABLE books ( title_id INT NOT NULL AUTO_INCREMENT, title VARCHAR(150), pages INT, PRIMARY KEY (title_id) );
CREATE TABLE authors ( author_id INT NOT NULL AUTO_INCREMENT, title_id INT NOT NULL, author VARCHAR(125), PRIMARY KEY (author_id) );
INSERT INTO table COLOMNS(列名) VALUES(値);
INSERT INTO books VALUES(1, "Linux in a Nutshell", 112); INSERT INTO authors VALUES(NULL, 1, "Ellen Siever"); INSERT INTO authors VALUES(NULL, 1, "Aaron Weber");
ALTER TABLE table_name RENAME new_table_name;
ALTER TABLE authors MODIFY author VARCHAR(150);
author_id 列の後に author 列を配置。 FIRST を指定すると、その列はテーブルの最初の列になる
ALTER TABLE authors MODIFY author varchar(125) AFTER author_id;
ALTER TABLE table_name ADD column_name DATA_TYPE;
AFTER column_name か FIRST で列を追加する場所を指定できる
AFTER TABLE table_name CHANGE new_column_name old_column_name varchar(125);
ALTER TABLE table_name DROP COLUMN column_name;
DROP TABLE table_name;
SELECT column_name FROM table_name [WHERE] [ORDER];
SELECT * FROM books WHERE title = "Classic Shell Scripting";
SELECT books.pages FROM books WHERE title = "Classic Shell Scripting";
SELECT * FROM authors ORDER BY author;
SELECT * FROM authors ORDER BY author DESC;
user_id と title_id の組み合わせに purchase_id を割り当てる purchases テーブルを作成してデータを追加する SQL
CREATE TABLE purchases ( purchase_id int NOT NULL AUTO_INCREMENT, user_id varchar(10) NOT NULL, title_id int(11) NOT NULL, purchased timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (purchase_id) ); INSERT INTO `purchases` VALUES(1, 'mdavis', 2, '2005-11-26 17:04:29'); INSERT INTO `purchases` VALUES(2, 'mdavis', 1, '2005-11-26 17:05:58');
著者名、ページ数、著者を一覧表示するクエリを作成する SELECT 文
SELECT books.*, author FROM books, authors WHERE books.title_id = authors.title_id;
SELECT 列 FROM テーブル JOIN 結合対象テーブル ON (条件);
SELECT * FROM books JOIN authors ON (books.title_id = authors.title_id);
テーブル名の後に AS と記述し、その後ろにエイリアスを指定する
SELECT * from books AS b, authors AS a WHERE b.title_id = a.author_id;
UPDATE books SET pages = 476 WHERE title = "Linux in a Nutshell";
DELETE FROM authors WHERE author_id = 1;
SELECT * FROM authors WHERE author LIKE "%b%";
SELECT * FROM authors WHERE author LIKE "Aaron Webe_";
WHERE 節のなかでは、AND / OR / NOT を使用できる
SELECT * FROM authors WHERE NOT (author = "Ellen Siever");
SELECT * FROM books, authors WHERE title = "Linux in a Nutshell" AND author = "Aaron Weber" AND books.title_id = authors.title_id;
SELECT *
FROM books, authors
WHERE (author = "Aaron Weber"
OR author = "Ellen Siever")
AND books.title_id=authors.title_id;
このクエリの括弧は重要。 AND 条件で authors テーブルと books テーブルを結合する前に、著者名の OR 条件を明確にする必要がある
[users] [ship]
User ------ User
First Address
Last City
State
Zip
(ry
(ry
| User ID | First name | Last name | Address | Phone | Title | Author1 | Author2 | Pages | When |
|---|---|---|---|---|---|---|---|---|---|
| Mdavis | Michele | Davis | Linksway, Fx Pnt | 414-352-4818 | Linux in a Nutshell | Ellen Siever | Aaron Weber | 112 | 2007/9/3 |
| Mdavis | Michele | Davis | Linksway, Fx Pnt | 414-352-4818 | Classic Shell Scripting | Arnold Robbins | Nelson Beebe | 576 | 2007/9/3 |
条件
正規化後
| User ID | Fitst name | Last name | Address | Phone | Title | Pages | When |
|---|---|---|---|---|---|---|---|
| Mdavis | Michele | Davis | Linksway, Fx Pnt | 414-352-4818 | Linux in a Nutshell | 112 | 2007/9/3 |
| Mdavis | Michele | Davis | Linksway, Fx Pnt | 414-352-4818 | Classic Shell Scripting | 576 | 2007/9/3 |
| Title | Author name |
|---|---|
| Linux in a Nutshell | Ellen Siever |
| Linux in a Nutshell | Aaron Weber |
| Classic Shell Scripting | Arnold Robbins |
| Classic Shell Scripting | Nelson Beebe |
| User ID | First name | Last name | Address | City | Stat | Zip code | Phone | Title | Pages | Date |
|---|---|---|---|---|---|---|---|---|---|---|
| Mdavis | Michele | Davis | 4505 N, Linksway | FxPnt | MN | 55114 | 414-352-4818 | Linux in a Nutshell | 112 | 2007/9/3 |
| Mdavis | Michele | Davis | 4505 N, Linksway | FxPnt | MN | 55114 | 414-352-4818 | Classic Shell Scripting | 576 | 2007/9/3 |
正規化後(Users Books Authors Purchases に分割された)
| Title_ID | Title | Pages |
|---|---|---|
| 1 | Linux in a Nutshell | 112 |
| 2 | Classic Shell Scripting | 576 |
| Author_ID | Author name |
|---|---|
| 1 | Ellen Siever |
| 2 | Aaron Weber |
| 3 | Arnold Robbins |
| 4 | Nelson Beebe |
| Title_ID | Author_ID |
|---|---|
| 1 | 1 |
| 1 | 2 |
| 2 | 3 |
| 2 | 4 |
| User_ID | First name | Last name | Address | City | State | Zip code | Phone |
|---|---|---|---|---|---|---|---|
| Mdavis | Michele | Davis | 7505 N. Linksway | FxPnt | MN | 55114 | 414-352-4818 |
| Purchase_ID | User_ID | Title_ID | When |
|---|---|---|---|
| 1 | Mdavis | 1 | 2007/9/3 |
| 2 | Mdavis | 2 | 2007/9/3 |
[]内は省略可
| フィールドタイプ | 説明 | 例 |
|---|---|---|
| INT[(M)] | 整数(Mは最大表示幅) | 997 |
| FLOAT[(M,D)] | 少数(最大M桁、小数点以下D桁) | 3.14142 |
| CHAR(M) | 文字列(M文字:最大255) | 「テスト」 |
| VARCHAR(M) | 文字列(M文字:最大255文字、MySQL 5 では 約 65000文字) | "testing 1.2.3" |
| TEXT or BLOB | 65535文字までの文字列 | "All work and no play makes Jack a dull boy." |
| DATE | YYYY-MM-DD | 2003-12-25 |
| TIME | HH:MM:SS | 11:36:02 |
| フィールド名 | データ型 |
|---|---|
| Title_ID | INT |
| Title | VARCHAR(150) |
| Pages | INT |
| フィールド名 | データ型 |
|---|---|
| Author_ID | INT |
| Title_ID | INT |
| Author | VARCHAR(100) |
store というデータベースをバックアップ & リストア:
$ mysqldump -u user -p store > my_backup_of_store.sql $ mysql -u root -p -D store < my_backup_of_store.sql
authors テーブルだけをバックアップする:
$ mysqldump -u root -p store authors > authors.sql
全データベースをバックアップ & リストア:
$ mysqldump -u root -p --all-databases > my_backup.sql $ mysql -u root -p < my_backup.sql
テスト用などに、データベースの状態を空の状態(構造のみ)で出力する:
$ mysqldump -u root -p --no-data store > structure.sql
データだけをバックアップ:
$ mysqldump -u root -p --no-create-info store > data.sql
CREATE UNIQUE INDEX authind ON authors (author);
EXPLAIN の出力には、どのようにクエリが処理されたかについて細かい情報が含まれる
EXPLAIN SELECT * FROM authors WHERE author = 'Arnold Robbins';
もっと改良の余地はありそうだが…ぐぬぬ
use common::sense;
use HTML::Entities;
our %re = (
uri => qr{(http://[\S]+)}, # FIXME
reply => qr{(\@[0-9A-Za-z_]+)},
hash => qr{(\#[0-9A-Za-z_]+)},
);
our $regex = qr/$re{uri}|$re{reply}|$re{hash}/;
my @tweets = (
"See: http://x.xx/@\"style=\"color:pink\"onmouseover=alert(1)//",
q{http://j.mp/dankogai @dankogai こうですか? #XSS わかりません <script>alert('XSS')</script>
http://twitter.com/search?q=a&r=b#@"onmouseover="alert(location.href)"/},
q{http://j.mp/dankogai @dankogai こうですか? #XSS わかりません <script>alert('XSS')</script>
http://twitter.com/search?q=a&r=b#@"onmouseover="alert(location.href)"/ twitpic! http://twitpic.com/2r2umf},
);
for my $tweet (@tweets) {
say '<div>';
say make_link($tweet);
say '</div>';
}
sub make_link {
my $text = decode_entities(shift);
my $html = '';
for my $token (split $regex, $text) {
if ($token =~ /^$re{uri}/) {
if ($token =~ m!http://twitpic\.com/(\w+)!) {
my $encoded = encode_entities($1);
$html .= qq{
<a href="http://twitpic.com/$encoded">
<img src="http://twitpic.com/show/thumb/$encoded"></a>};
} else {
my $encoded = encode_entities($token);
$html .= qq{<a href="$encoded">$encoded</a>};
}
} elsif ($token =~ m!^\#(.+)$!) {
my $hash_ent = encode_entities($1);
my $hash_tag = encode_entities($token);
$html .= qq{<a href="http://search.twitter.com/search?q=%23$hash_ent">$hash_tag</a>};
} elsif ($token =~ m!^\@(.+)$!) {
my $user = encode_entities($1);
$html .= qq{<a href="http://twitter.com/$user">\@$user</a>};
} else {
$html .= encode_entities($token);
}
}
return $html;
}
exit;
__END__
$ git init fatal: cannot copy /usr/share/git-core/templates/info/exclude to /tmp/foo/.git/info/exclude
このエラー出た人は他にいるのかなぁ。
こんな風にパーミッションを変更してやればよい
# cd /usr/share/git-core/templates # find | xargs chmod +r
Emacs 使ってる人に dis られた挙句涙目で散々調べまわって苦労した。
cpanm Vi::QuickFix
http://www.vim.org/scripts/script.php?script_id=896
この二つを真(1)に書き換える
let s:default_perl_synwrite_qf = 1 let s:default_perl_synwrite_au = 1
これは各自お好きなように。
" quickfix map <silent><C-c> :cn<CR> map <silent><C-l> :cl<CR>
use strict; use warnings; use 5.12.1; say $foo;
を :w で書き込もうとすると
Global symbol "$foo" requires explicit package name at - line 7. - had compilation errors. shell returned 255 Press ENTER or type command to continue
と出て保存できない。yatta.
Test::TCP 1.03 が出てるので上げておくといいと思います。 Test::TCP 1.02 をテストで使うモジュールをインストールすると、 ~/.cpanm/build.log に
cannot open port: 10033 at /home/foo/perl5/perlbrew/perls/perl-5.12.1/lib/site_perl/5.12.1/Test/TCP.pm line 117.
と出てテストが通らないが、バージョン上げることで解決可。
既出かもしれないけれど。
run スクリプトで環境変数を export してあげないと perlbrew の利点を活かしきれない。ちなみに bash を中心に扱っているので、自分の環境に合わせて読み替えてください。
perlbrew init したときに ~/.bashrc に追記した source の行があるはずなのでそれを辿って export を run にコピペしてやればよい。
$ cat ./bashrc
..snip...
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
source /home/foo/perl5/perlbrew/etc/bashrc
$ cat /home/foo/perl5/perlbrew/etc/bashrc
export PATH=/home/foo/perl5/perlbrew/bin:/home/foo/perl5/perlbrew/perls/current/bin:${PATH}
$ cat /etc/service/chirp/run
#!/bin/sh
cd /home/foo/chirp
export PATH=/home/foo/perl5/perlbrew/bin:/home/foo/perl5/perlbrew/perls/current/bin:${PATH}
exec setuidgid foo perl chirp.pl
としておく。これで perlbrew switch したバージョンを使えるようになる。
※ $^V を表示するテストスクリプトを走らせて確認しておくことで、嵌ることを回避できる
クラウド破産を回避できたり、自宅サーバを守れるというメリットがあるらしいので、どうせなら epoll を使ってみようということで。
http://d.hatena.ne.jp/odz/20070507/1178558340 と http://alpha.mixi.co.jp/blog/?p=76 と man が参考に。某所経由で id:koizuka 氏にいろいろ教わり助かりました。
nginx 速すぎで大変悲しい結果に。
http://d.hatena.ne.jp/odz/20070507/1178558340 の勝手 fork です。問題/間違い等あれば連絡いただければありがたいです。エラー処理は省略気味。
それぞれ debian 上で epoll_sample, nginx, Apache2 を実行。nginx, apache2 ともに apt-get install で持ってきて設定はデフォルトのまま。
# ab -n 10000 -c 50 http://localhost:8080/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software:
Server Hostname: localhost
Server Port: 8080
Document Path: /
Document Length: 7 bytes
Concurrency Level: 50
Time taken for tests: 20.125 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 710142 bytes
HTML transferred: 70014 bytes
Requests per second: 496.91 [#/sec] (mean)
Time per request: 100.623 [ms] (mean)
Time per request: 2.012 [ms] (mean, across all concurrent requests)
Transfer rate: 34.46 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 3 46 12.6 46 117
Processing: 9 48 13.8 48 241
Waiting: 0 32 15.2 35 239
Total: 32 95 23.2 94 244
Percentage of the requests served within a certain time (ms)
50% 94
66% 96
75% 99
80% 101
90% 109
95% 135
98% 168
99% 178
100% 244 (longest request)
# ab -n 10000 -c 50 http://localhost:80/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: nginx/0.6.32
Server Hostname: localhost
Server Port: 80
Document Path: /
Document Length: 151 bytes
Concurrency Level: 50
Time taken for tests: 22.493 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 3627602 bytes
HTML transferred: 1513171 bytes
Requests per second: 444.58 [#/sec] (mean)
Time per request: 112.465 [ms] (mean)
Time per request: 2.249 [ms] (mean, across all concurrent requests)
Transfer rate: 157.50 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 3 54 9.6 53 128
Processing: 33 57 11.1 54 139
Waiting: 7 46 12.1 46 134
Total: 64 112 15.2 107 230
Percentage of the requests served within a certain time (ms)
50% 107
66% 111
75% 113
80% 114
90% 119
95% 146
98% 171
99% 182
100% 230 (longest request)
# ab -n 10000 -c 50 http://localhost:80/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Apache/2.2.9
Server Hostname: localhost
Server Port: 80
Document Path: /
Document Length: 45 bytes
Concurrency Level: 50
Time taken for tests: 31.275 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 3204993 bytes
HTML transferred: 452115 bytes
Requests per second: 319.74 [#/sec] (mean)
Time per request: 156.377 [ms] (mean)
Time per request: 3.128 [ms] (mean, across all concurrent requests)
Transfer rate: 100.07 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 46 74 16.8 70 194
Processing: 51 81 16.9 81 211
Waiting: 3 52 28.2 53 172
Total: 138 155 20.2 149 401
Percentage of the requests served within a certain time (ms)
50% 149
66% 153
75% 156
80% 158
90% 169
95% 198
98% 230
99% 238
100% 401 (longest request)
Adblock Plus -> 設定 -> 追加 で要素非表示フィルタに
twitter.com###recommended_users
を追加して有効にすればよい
ですが、実際どう使うのかという点ではまだまだ明文化されたものが少ないと思ったので http://xslate.org/intro.html を書いておきました。記事では、イテレーションをはじめ知っておくと便利な dump フィルタ、 mark_raw() がテーマになっています。近々トップページからリンクされる模様。
サンプルコードは id:gfx さんの手が入っているので安心のクォリティ。サンプルを見れば特に英語自体は読まなくても大丈夫です。