2006-01-01から1年間の記事一覧

アルゴリズムの問題いろいろ

合計金額になるすべてのお金の組み合わせを計算する。 例:10ドル、5ドル、1ドルを組み合わせて123ドルになるのは何通り? use strict; sub f{ my( $amount, @curs ) = @_; my $cur = shift @curs; my $total; return 0 unless $cur; if( @curs == 0 ) { …

sshのrootのログインの禁止

SSH

/etc/ssh/sshd_config を以下のように修正する PermitRootLogin yes <- rootログインあり PermitRootLogin no <- rootログイン無し PermitRootLogin forced-commands-only <- rootでも特定のコマンドのみアクセス許可/root/.ssh/authorized_keys のサンプル …

find の使い方メモ

# find -name ".svn" -exec rm -rf {} \; # "foo bar/" のような空白を含むファイル名の場合に動作しない # find . -name ".svn" -print |xargs rm -rf # ヌル文字をセパレータにしてから、xargsに渡し、xargsでは、-0 により、ヌル文字区切りを認識する。 #…

Bashメモ

ディレクトリ一覧 find . -type d |sed 's!^\./!!' 日付を表示 date +\%Y\%m\%d 配列 と forループ AA=(aa bb cc dd ee) for a in ${AA[@]}; do echo $a done 1行で。 for d in `ls`; do コマンド; done for i in `seq 1 10`; do mysql -e "select count(*) …

バックアップ&リストア Backup & Restore

/usr/bin/mysqldump -u root -p\'$pass\' --flush-logs \ --delete-master-logs --all-databases | /usr/bin/gzip > /backup/$server/dbdump.sql.gz

date コマンドメモ

# date +%Y%m%d 20060811 # date +%Y%m%d -d '1 day ago' 20060810

[Postfix] telnetでテスト

SMTP # telnet smtp.example.com 25 HELO mymachine MAIL FROM: <from@example.com> RCPT TO: <to@example.com> DATA From: from@example.com To: to@example.com Subject: TEST mail body is here. . QUIT ||< -SMTP Auth >|| 220 smtp.example.com ESMTP EHLO [10.0.7.1] 250-smtp.example.co</to@example.com></from@example.com>…

NICに複数のIPアドレスを追加する。

ifconfig eth0:1 192.168.0.101 netmask 255.255.255.0 up ifconfig eth0:2 192.168.0.102 netmask 255.255.255.0 up ifconfig eth0:3 192.168.0.103 netmask 255.255.255.0 up

pear::Mail::mimeDecode で、multipart/mixed のメールで、「boundary」の終わりがない場合に最後のパートが消えてしまう問題の回避方法。

PHP

オリジナルのソース: mimeDecode.php $tmp = explode('--' . $boundary, $input); for ($i = 1; $i < count($tmp) - 1; $i++) { $parts[] = $tmp[$i]; }変更後のソース: mimeDecode.php $tmp = explode('--' . $boundary, $input); if( count($tmp) == 2 ) $…

How to make a self-signed certificate 自己署名の作成方法

http://www.kozupon.com/security/ssl_source.html

refererによるアクセス制限

httpd.conf を以下のように編集する <Directory /> Options FollowSymLinks # AllowOverride None AllowOverride All <- これ </Directory> 例 http://www.hatena.ne.jp/以下のページからのリンクのみ許可 SetEnvIf Referer "^http://www\.hatena\.ne\.jp" ref_ok order deny,allow de…

関数メモ

pack, unpackの使い方 print unpack('H*', '@gmail.com'); 40676d61696c2e636f6d print pack('H*', '40676d61696c2e636f6d'); @gmail.com print unpack('h*', '@gmail.com'); <--hだとエンディアンが逆になる。 0476d61696c6e236f6d6 print pack('h*', '0476…

時間の同期

1時間に一度、タイムサーバーと時刻を同期するコマンドを、cronに登録。 # crontab -lcron編集画面で以下のように設定。 58 * * * * /usr/sbin/ntpdate -s clock2.redhat.com

my.cnf/my.ini ファイル

メモリ1GBのMySQLのサンプル [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Default to using old password format for compatibility with mysql 3.x # clients (those using the mysqlclient10 compatibility package). old_passwo…

Hello World

ASP

<html> <body> <% Response.Write "Hello World" %> </body> </html>

Apache2::Reload で自動リロード

/etc/httpd/conf.d/ の適当な設定ファイルに以下を追加。 PerlModule Apache2::Reload PerlInitHandler Apache2::Reload PerlSetVar ReloadDirectories "/var/www/mod_perl" PerlSetVar ReloadDebug On

[]バイト数カウント(Shift_JIS EUC用)

IEの改行は、\r\nになる。 FFの改行は、\nになる。 function getByteCount(s) { var i=0; var nBytes=0; for(i=0;i<s.length;i++){ if(s.charAt(i)=='\n') nBytes++; else if(s.charAt(i)=='\r') ; //カウントしない else if( s.charCodeAt(i)>255 )nBytes+=2; else nBytes++; } return nBytes; }</s.length;i++){>

E-mailアドレスの正規表現

/^[\w\-]+\.?[\w\-]+@([\w\-]+\.)+[\w\-]+$/

全角チェック

if( form.e.value.match(/[ .,;:’”@#$%^&*()+−=A-zあ-んア-ンア-ンー]/) ) { alert("全角"); }

TCPのウィンドウサイズの変更方法

/proc/sys/net/core/rmem_default で設定できる。 routeコマンドで実行中にも変更できる。

SELinuxの無効化

/etc/sysconfig/selinux を開く SELINUX=enforcing SELINUXTYPE=targetedを以下のようにする。 SELINUX=disabled #SELINUXTYPE=targeted

SafariでJavaScriptのデバッグ

Mac

コンソールを開いて defaults write com.apple.Safari IncludeDebugMenu 1Debugメニューが表示される。

文法メモ

Tag Name Contains Substitution Perl that is evaluated and sent as output % ... Perl line A single line of Perl code perl> ... Perl block Perl code Component call A call to another component, possibly with arguments ... init block Perl code…

Masonの設定

/etc/httpd/conf.d/mason.conf を以下のように作成 PerlModule HTML::Mason::ApacheHandler <LocationMatch "\.html$"> SetHandler perl-script PerlHandler HTML::Mason::ApacheHandler </LocationMatch>これで、拡張子が.htmlのファイルがMasonで処理される。

Perl ワンライナー メモ

複数行にまたがる文字列置き換え 例: 以下から <select name="timezone"> <option value="a">... <option value="b">... <option value="c">... </select> ここまでをfooに置き換える。 以下は置き換えない。 <select name="other"> <option value="a">... <option value="b">... <option value="c">... </select>以下のスクリプトでok perl -p -0777 -i.bak -e "s#

IIS上でPHPを動かす

PHP

phpをダウンロードして解凍する。 php というフォルダの中に解凍して、InetPub/Scripts/php に置く。 別の場所でも良いが、アクセス権をゆるくしておかないと、ユーザ名とパスワードを聞かれることがあるので注意。 WWWサーバーのプロパティで、「Home Direc…

Fedora Core 5 上でのmod_perlのセットアップ

オリジナルは、naoyaの「10分で完了、mod_perl 2.0 で Hello, World!」d:id:naoya:20060108:1136692447/etc/httpd/conf.d/naoya.conf という名前で以下を作成 NameVirtualHost *:80 <VirtualHost *:80> ServerName fc5:80 PerlModule mod_perl PerlRequire /var/www/mod_perl/s</virtualhost>…

MSDNメモ

Subscribers -> not your subscription? -> Sign in

Perlメモ

@array = (1, 3, 5); # 配列 $ref = [1, 3, 5]; # 配列の参照 @array == @{$ref} == @$ref; # 全部等しい \@array と $ref は、値は同じ。 デバッグ用 use Data::Dumper; print Dumper( @array ); perl -d のxコマンド相当 データの永続化 use Storable; sto…

10分以上アクセスのないセッションを削除する

PHP

cron に以下を設定する。 5,15,25,35,45,55 * * * * cd /var/lib/php/session/; find -amin +10 -exec rm -f {} \;find のexec は、「;」で終わる必要あり。 find の「{}」には、find でマッチしたファイル名が入る。 shellが、; を理解できるように、「\;」…