十一月 12
|
Action
|
apt-get command
|
aptitude command
|
|
Install foo
|
apt-get install foo
|
aptitude install foo
|
|
Search foo
|
apt-cache search foo
|
aptitude search foo
|
|
Remove foo
|
apt-get remove foo
|
aptitude remove foo
|
|
List reverse dependencies
|
apt-cache rdepends foo
|
aptitude ~D foo
|
|
Print information on priorities for foo
|
apt-cache policy foo
|
?
|
|
Download foo’s sources and build a binary .deb package
|
apt-get source –compile foo
|
?
|
How to upgrade your distribution
Find out current version of Debian that you are running:
Example for upgrading sarge to etch or etch 4.0r1 to 4.0r2 …etc
來源:Aptitude – Debian Wiki
Tagged with: cli • tips • Unix-like
十一月 12
因為用 Leopard 內建的 Python 在互動模式下中文有問題
所以來用 MacPorts 裝 Python 2.6,裝好之後出現
To fully complete your installation and make python 2.6 the default, please run
sudo port install python_select
sudo python_select python26
python_select:Switch the default python interpreter
指令照打沒效=.=
還是自己作連結比較保險
sudo ln -s /opt/local/bin/python python
Tagged with: cli • osx • Python • tips • Unix-like
十一月 05
tchinese.py
#!/bin/python
print "Python是個酷玩意"
python tchinese.py
SyntaxError: Non-ASCII character '\xe6' in file tchinese.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
錯誤訊息中的連結到這篇文章:PEP 0263 — Defining Python Source Code Encodings
文中提到:
To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file, such as:
or (using formats recognized by popular editors)
#!/usr/bin/python
# -*- coding: <encoding name> -*-
or
#!/usr/bin/python
# vim: set fileencoding=<encoding name> :
Example:
#!/bin/python
# -*- coding: utf-8 -*-
print "Python是個酷玩意"
Result:
Tagged with: CJKV • Programming • Python • tips • UTF-8
十一月 03
-h ”Human-readable” output. Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte.
-s Display an entry for each specified file. (Equivalent to -d 0)
-d depth
Display an entry for all files and directories depth directories deep.
只列出目錄大小:
du -sh ~/Documents/EyeTV\ Archive/
3.2G /Users/name/Documents/EyeTV Archive/
列出目錄裡該層所有檔案大小:
du -sh ~/Documents/EyeTV\ Archive/*
4.0K /Users/name/Documents/EyeTV Archive/EyeTV Archive.xml
4.0K /Users/name/Documents/EyeTV Archive/EyeTVAutoTune.log
3.2G /Users/name/Documents/EyeTV Archive/熱帶魚 – 單元集單元劇.eyetv
25M /Users/name/Documents/EyeTV Archive/伊索動物劇場 – 第17集偶戲動畫卡通獅子和山豬.eyetv
Tagged with: cli • tips • Unix-like
十一月 02
PHP 檔案處理
讀檔:
1.fopen
範例:
<?php
$handle = fopen("open_file.txt", "r");
if( $handle === FALSE)
{
echo "Open File Fail" . "<br>";
}
else
{
echo "Open File Success" . "<br>";
while (!feof($handle))
{
$current_line = fgets($handle);
echo $current_line . "<br>";
}
}
?>
2.file_get_contents
範例:
<?php
$handle = file_get_contents('open_file.txt');
echo $handle;
?>
=========================================================
寫檔:
1.fwrite
<?php
$handle = fopen('open_file.txt', 'w');
fwrite($handle, "test1");
fclose($fp);
?>
ps:fwrite 是沒有加換行字元,如果要換行必須加上 \n 處理
2.file_put_contents
<?php
$handle = 'open_file.txt';
$current_line = "line1\n";
file_put_contents($handle, $current_line);
?>
source: PHP:檔案處理 @ 拉不拉多的夢幻世界 :: 痞客邦 PIXNET ::
Tagged with: PHP • Programming • tips
十月 26
方便的自動安裝
perl -MCPAN -e 'install full::module::name'
但我試了幾次很容易會在 fetch ftp 來源的 source code 時卡住,要重試幾次。
手動編譯
tar xzvf example-<version>.tgz
cd example-<version>
perl Makefile.PL
make
make test
make install
搜尋WP::UserAgent模組
重新配置cpan
cpan> o conf init
cpan> reload index
驗證安裝了沒
perl -e 'require LWP::UserAgent'
update: 有時候,還是需要加個 sudo 確保有權限將檔案放入系統
Tagged with: Perl • tips
最新回應