2012年5月31日 星期四

burn iso though cui

emerge -av dvd+rw-tools


growisofs -dvd-compat -Z /dev/dvdrw=/root/yourImage.ISO -speed=4

2012年5月24日 星期四

Linux登出之後,讓程式繼續執行的方法

nohup yourCommand

Refer:
http://dragonspring.pixnet.net/blog/post/33257496-%5Blinux%5Btips%5Dnohup%3A-%E8%AE%93command%E5%9C%A8%E9%81%A0%E7%AB%AF%E5%9F%B7%E8%A1%8C%EF%BC%8C%E4%B8%8D%E5%9B%A0%E7%99%BB%E5%87%BA
http://franks543.blogspot.com/2008/02/linux.html

2012年5月10日 星期四

Set default search behavior in opera address bar

Go to opera:config#network
Disable "Check Local HostName"
Disable "Enable HostName Expansion"
Enable "Enable HostName Web Lookup"

from: http://my.opera.com/remcolanting/blog/2009/02/24/single-word-search-in-the-opera-address-bar

2012年5月2日 星期三

金句-Fight Club

我找到了自由,拋開所有希望就是自由
I found freedom. Losing all hope was freedom. 

我要到洞裡找我的精神動物
不要用快死的人的方式躲避疼痛

我在這裡看到了最強最聰明的人
你們都很有潛力
但都被浪費了
你們只是做一些替人加油
或是上菜
或是打領帶上班的工作
廣告誘惑我們買車子、衣服
於是拚命工作買不需要的東西
我們是被歷史遺忘的一代
沒有目的
沒有地位
沒有世界大戰
沒有經濟大恐慌
我們的大戰只是心靈之戰
我們的恐慌只是我們的生活
我們從小看電視
相信有一天
會成為富翁、明星或搖滾巨星
但是…我們不會
那是我們逐漸面對著的現實
所以我們非常憤怒

抛棄一切…才有自由
No fear. No distractions.

工作不能代表你
You are not your job
銀行存款其不能代表你
You're not know much money you have in the bank
你開的車也不能代表你
You're not the car you drive
皮夾裡的東西不能代表你
You're not the contents of your wallet
衣服也不能代表你
You're not your fucking khakis
你只是平凡眾生中的其中一個
You are the all-singing, all-dancing crap of the world

2012年4月30日 星期一

七二法則

七二法則是用於計算在某段時間之內成長到原有價值兩倍的方法。

倍數成長年限=72/成長率

真是這麼神奇?


Code:

import math
print (('%5s %5s %5s') % ('%', '72/I', 'Actual Year'))
for i in range(1, 101):
actual = 0
j = 1
k = 1+i/100
while j < 2:
j *=k
actual += 1
print (('%5d %5d %5d') % (i, math.floor(72/i), actual))

Result:

% 72/I Actual Year
1 72 70
2 36 36
3 24 24
4 18 18
5 14 15
6 12 12
7 10 11
8 9 10
9 8 9
10 7 8
11 6 7
12 6 7
13 5 6
14 5 6
15 4 5
16 4 5
17 4 5
18 4 5
19 3 4
20 3 4
21 3 4
22 3 4
23 3 4
24 3 4
25 2 4
26 2 3
27 2 3
28 2 3
29 2 3
30 2 3
31 2 3
32 2 3
33 2 3
34 2 3
35 2 3
36 2 3
37 1 3
38 1 3
39 1 3
40 1 3
41 1 3
42 1 2
43 1 2
44 1 2
45 1 2
46 1 2
47 1 2
48 1 2
49 1 2
50 1 2
51 1 2
52 1 2
53 1 2
54 1 2
55 1 2
56 1 2
57 1 2
58 1 2
59 1 2
60 1 2
61 1 2
62 1 2
63 1 2
64 1 2
65 1 2
66 1 2
67 1 2
68 1 2
69 1 2
70 1 2
71 1 2
72 1 2
73 0 2
74 0 2
75 0 2
76 0 2
77 0 2
78 0 2
79 0 2
80 0 2
81 0 2
82 0 2
83 0 2
84 0 2
85 0 2
86 0 2
87 0 2
88 0 2
89 0 2
90 0 2
91 0 2
92 0 2
93 0 2
94 0 2
95 0 2
96 0 2
97 0 2
98 0 2
99 0 2


結論:
成長率在6或以下就準確,在7到36需要加1

2012年4月23日 星期一

Some install record concerning mod_wsgi on gentoo

Target: Using Virtual Server (I called it prototype :) ).

Request modify the hosts file

/etc/apache2/modules.d/70_mod_wsgi.conf

# WSGISocketPrefix is require 'mkdir /usr/lib/apache2/run'
WSGISocketPrefix
#WSGIPythonOptimize enable output the pac file
WSGIPythonOptimize 1
WSGILazyInitialization Off
#WSGIImportScript path process-group=prototype application-group=prototype
#WSGIPythonHome
#WSGIPythonPath


/etc/apache2/vhosts.d/00_default_vhost.conf

<VirtualHost *:80>
ServerName prototype
ErrorLog /var/log/apache2/prototype_error_log
CustomLog /var/log/apache2/prototype_access_log common

Include /etc/apache2/vhosts.d/prototype.include

<IfModule mpm_peruser_module>
ServerEnvironment apache apache
</IfModule>
</VirtualHost>



/etc/apache2/vhosts.d/prototype.include

ServerAdmin masked@masked
DocumentRoot "/var/www/prototype/htdocs"
<Directory "/var/www/prototype/htdocs">
# Enable AllowOverride in order to use '.htaccess' to modify the access right on the fly
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# Using Alias since mount the DocumentRoot as root "...any static files contained in the DocumentRoot will be hidden and requests against URLs pertaining to the static files will instead be processed by the WSGI application. from:http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide"

Alias /favicon.ico /var/www/prototype/htdocs/favicon.ico
Alias /media/ /var/www/prototype/htdocs/media/

WSGIScriptAlias / /var/www/prototype/htdocs/wsgi_script/runme.py
WSGIDaemonProcess prototype:1 processes=2 threads=15 display-name=%{GROUP} user=prototype group=prototype umask=0022 maximum-requests= 1024 deadlock-timeout=5 shutdown-timeout=3 receive-buffer-size=87380 send-buffer-size=65536
#-WSGIDaemonProcess
WSGIProcessGroup prototype:1
WSGIRestrictProcess prototype:1


/var/www/prototype/htdocs/wsgi_script/runme.py

import sys

def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

print >> sys.stderr, 'sys.prefix = %s' % repr(sys.prefix)
print >> sys.stderr, 'sys.path = %s' % repr(sys.path)

return [output]


All dir/.htaccess

AddDefaultCharset utf-8
# Disable directory index
Options -All

Run Home bashrc

all below lines attached the file /etc/bash/bashrc

#enable personally bashrc
if [[ ~/.bashrc ]] ; then
source ~/.bashrc
fi


Example

#!/bin/bash
alias ncat='nano -v'

Kick user/ terminal on linux

## show user
~# w
##
## kick terminal
~# skill -KILL -v pts/0
##
## kick user
~# skill -KILL -u user
##
## Stop/Pauseuser activites
~# skill -STOP -u user
##
## Resume a stopped user
~# skill -CONT -u user

http://servercomputing.blogspot.com/2012/01/kill-and-logout-users-in-pts-linux.html

Enable key pad in termal

/etc/profile.d/term.sh


#!/bin/bash
# This program change term to vt220 for enable num pad on terminal
# The side effect is the page up/down be unavailable in nano editor
# The default value is xterm
# list all available on /etc/terminfo
TERM=vt220


Refer:http://www.linuxquestions.org/questions/*bsd-17/problem-with-remote-terminal-ssh-and-putty-125363/

The quicker way of run cmd with administrator rights

  1. Press Win Key
  2. Type cmd
  3. Combine to press Ctrl + Shift + Enter


Refer:http://fasterdata.es.net/host-tuning/ms-windows/

2012年4月22日 星期日

Edit remote *nix text file on windows using Notepad++

Notepad++ with the useful plugin - NppFtp
Step:
  1. Plugin->NppFtp->Show NppFtp windows
  2. On NppFtp windows, click 'Gear' (Settings) icon->Profile settings
  3. Add new a new profile, below is recommend settings
    Cache
    Local path:
    %temp%\nppftp
    Ext path: /tmp/nppftp
    Transfers-
    Transfer mode
    Binary
Using Unix Document Format:
Either set default using Unix Document Format when create a new document (Settings, Preferences, New Document/Default Directory)
or set the current document to Unix format (Edit, EOL Conversion, Convert to Unix format)

When edit the python script file. Using UTF-8 without BOM. Rather than UTF8 and ANSI.

Refer:http://sourceforge.net/projects/notepad-plus/forums/forum/331754/topic/3498612

2012年4月18日 星期三

Save power through dynamic frequency

the program split in 2 part:
a program set something and call the script to manage the frequency

/etc/local.d/powerSave.start

#!/bin/bash

#Runtime Power Management
for i in `find /sys/devices/*/power/control`; do echo auto > $i; done;

#USB Autosuspend
for i in `find /sys/bus/usb/devices/*/power/level`; do echo auto > $i; done;
for i in `find /sys/bus/usb/devices/*/power/autosuspend`; do echo 2 > $i; done;

#Use script to mgmt the frequency
cpufreq-set -r -g userspace
echo `date +"%a %b %d %T"` dynamicFrequency start >> /var/log/dynamicFrequency.log
/sbin/dynamicFrequency.py



/etc/local.d/powerSave.stop

#!/bin/bash
kill $(cat /var/run/dynamicFrequency.pid)
cpufreq-set -r -g performance
echo `date +"%a %b %d %T"` dynamicFrequency Stop >> /var/log/dynamicFrequency.log


/sbin/dynamicFrequency.py

#!/usr/bin/python3.2
"""\
This program select a scaling available frequencies based on loadavg
for example the available frequencies:
350000 700000 1050000 1400000 1750000 2100000 2450000 2800000
the current frequencies is 175000
if load >= 80% the frequencies jump 2 step (245000)
if load >= 60% the frequencies jump 1 step (210000)
if load < 20% the frequencies jump -2 step (1050000)
if load < 40% the frequencies jump -1 step (1400000)


"""

import os

# Write the pid into
pid_path = '/var/run/dynamicFrequency.pid'

pidFile=None
if os.path.exists(pid_path):
pidFile = open(pid_path, 'w')
else:
pidFile = open(pid_path, 'a')

pidFile.write(str(os.getpid()))
pidFile.close()

scaling_available_frequencies = None
with open('/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies', 'r') as file:
scaling_available_frequencies = file.read().strip().split()

current_frequencies = None
with open('/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq', 'r') as file:
raw_current_frequencies = file.read().strip()
if raw_current_frequencies in scaling_available_frequencies:
current_frequencies = scaling_available_frequencies.index(raw_current_frequencies)
else:
current_frequencies = len(scaling_available_frequencies)

from decimal import *
from time import sleep

max = len(scaling_available_frequencies) - 1

while True:
loadavg = None
with open('/proc/loadavg', 'r') as file:
loadavg = Decimal(file.read().strip()[0])

change = 0
if loadavg >= Decimal(0.80):
change = 2
elif loadavg >= Decimal(0.60):
change = 1
elif loadavg < Decimal(0.20):
change = -2
elif loadavg < Decimal(0.40):
change = -1

plan=None
if current_frequencies + change >= max:
plan = max
elif current_frequencies + change < 0:
plan = 0
else:
plan = current_frequencies + change

if plan != current_frequencies:
current_frequencies = plan
with open('/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed', 'w') as file:
file.write(scaling_available_frequencies[current_frequencies])
os.system('echo `date +"%a %b %d %T"` dynamicFrequency' + ' loadavg:' + str(loadavg) + ' change frequency to:' + \
scaling_available_frequencies[plan] + ' >> /var/log/dynamicFrequency.log')

sleep(5)

Reference:

2012年4月15日 星期日

Calculate range number either prime number

import math
for n in range(2, 100):
 o = n
 s = set()
 i = 2
 j = math.floor(n)
 while i < j:
  if o % i == 0:
   s.add(i)
   o //= i
  else:
   i+=1
 if len(s):
  print(n, ':' ,','.join(str(v) for v in sorted(s)))
 else:
  print(n, ' is a prime number')


2  is a prime number
3  is a prime number
4 : 2
5  is a prime number
6 : 2,3
7  is a prime number
8 : 2
9 : 3
10 : 2,5
11  is a prime number
12 : 2,3
13  is a prime number
14 : 2,7
15 : 3,5
16 : 2
17  is a prime number
18 : 2,3
19  is a prime number
20 : 2,5
21 : 3,7
22 : 2,11
23  is a prime number
24 : 2,3
25 : 5
26 : 2,13
27 : 3
28 : 2,7
29  is a prime number
30 : 2,3,5
31  is a prime number
32 : 2
33 : 3,11
34 : 2,17
35 : 5,7
36 : 2,3
37  is a prime number
38 : 2,19
39 : 3,13
40 : 2,5
41  is a prime number
42 : 2,3,7
43  is a prime number
44 : 2,11
45 : 3,5
46 : 2,23
47  is a prime number
48 : 2,3
49 : 7
50 : 2,5
51 : 3,17
52 : 2,13
53  is a prime number
54 : 2,3
55 : 5,11
56 : 2,7
57 : 3,19
58 : 2,29
59  is a prime number
60 : 2,3,5
61  is a prime number
62 : 2,31
63 : 3,7
64 : 2
65 : 5,13
66 : 2,3,11
67  is a prime number
68 : 2,17
69 : 3,23
70 : 2,5,7
71  is a prime number
72 : 2,3
73  is a prime number
74 : 2,37
75 : 3,5
76 : 2,19
77 : 7,11
78 : 2,3,13
79  is a prime number
80 : 2,5
81 : 3
82 : 2,41
83  is a prime number
84 : 2,3,7
85 : 5,17
86 : 2,43
87 : 3,29
88 : 2,11
89  is a prime number
90 : 2,3,5
91 : 7,13
92 : 2,23
93 : 3,31
94 : 2,47
95 : 5,19
96 : 2,3
97  is a prime number
98 : 2,7
99 : 3,11

2012年4月13日 星期五

Use tty1 to see log

/etc/lilo.conf
add below line under the default. It mean use 800x600 (32bpp)
vga=0xF07



/sbin/tailLog
#!/bin/bash
#no blank screen
setterm -blank 0
# use bigger font
setfont /usr/share/consolefonts/UniCyr_8x14.psf.gz
tail -f /var/log/messages


modify the /etc/inittab

Edit the row:
c1:12345:respawn:/sbin/agetty 38400 tty1 linux

>
c1:12345:respawn:/sbin/agetty 38400 tty1 linux -n -l /sbin/tailLog

Gentoo Network Configuration

/etc/conf.d/net
# This blank configuration will automatically use DHCP for any net.*
# scripts in /etc/init.d. To create a more complete configuration,
# please review /usr/share/doc/openrc*/net.example* and save your configuration
# in /etc/conf.d/net (this file :]!).
modules="ifconfig"
dns_servers_eth0="192.168.1.254"
config_eth0="192.168.1.234 netmask 255.255.255.0"
routes_eth0="default via 192.168.1.254"


/etc/sysctl.conf

#append this row
kernel.domainname = local


/etc/conf.d/hostname

# Set to the hostname of this machine
hostname="gentoo"

Cannot mount boot partition (ext2)

Solution:
#tune2fs -O has_journal /dev/sda1

lilo: One warning was issued

#/sbin/lilo -v
LILO version 22.8, Copyright (C) 1992-1998 Werner Almesberger
Development beyond version 21 Copyright (C) 1999-2006 John Coffman
Released 19-Feb-2007 and compiled at 09:05:22 on Apr 11 2012

Warning: LBA32 addressing assumed
Reading boot sector from /dev/sda
Using MENU secondary loader
Calling map_insert_data

Boot image: /boot/linux-3.2.1-gentoo-r2
Added gentoo

Boot image: /boot/linux-3.2.2-hardened-r1
Added hardened *
Writing boot sector.
/boot/boot.0800 exists - no boot sector backup copy made.
One warning was issued.

Try
#sbin/lilo -L -S /boot/boot.0800

2012年4月9日 星期一

金句-白色相簿

6
忘卻煩惱得好辦法,對別人的麻煩插上一手如何?

11
占據胸口我煩惱,時間不會將其解決,只是貼上忘卻的標簽而已。
健忘,據說是替換成了更不能忘記的重要東西

14
音色無法調至完美,因為總能找到更好的

2012年3月25日 星期日

金句-尋求自我

03-86
「個體」在「種」面前非常無力,你不覺得不甘心嗎?

03-110
人生就像自慰。摩擦愈多就愈爽快。
你也要一直摩擦著。
沒有摩擦,什麼都無法產生。

03-136
人的能力並非無限,有所得就有所失。
可要作好這層心理準備。

03-188
數學家兼哲學家帕斯卡就說過
「想像力左右一切」

03-190
但沒經驗的初學者隨便跳進這個坑,一個弄不好可會弄出人命的。

03-200
尋找自己的嗜好,就宛如尋求自的一般。
在混亂之中做出選擇與取捨,探尋自己的追求的東西。

04-Cover
沉溺於自己的所作所為卻反而喪失自己時,唯一能確定的是…去找你的出路吧!

04-107
自忍的真髓在於自我中心。

04-113
享受孤獨,就該時自慰。

04-132
一旦長大成人,就要有很大的膽量才能熱衷於一件事…

04-235
又不是天人永別,只要還活著,早晚能再碰面。

金句-天降之物

第一季
04
爺爺
小智聽好 好好聽爺爺說的話
你已經是男人了
總有一天你會像爺爺一樣
有一個喜歡得不能再喜歡的東西出現
但是 它終有一天會向你露出獠牙也說不定
到那時候你該怎麼辦?
掉頭就跑嗎
不是的吧 小智
謝謝你 爺爺
我 終於醒悟了

08
15世紀開始的大航海時代
也可以說是西歐列強殘酷無道的殖民活動
歐洲人右手握著槍桿
左手握著聖經
右手握著槍
接二連三地發現新大陸
並對其展開武力侵略
人類首次拿起的火槍
才是征服新大陸的象徵