2012年8月24日 星期五

set java path and classpath in bat file

set path=%path%+;C:\Program Files\Java\jre7\bin
set classpath=C:\Program Files\Java\jre7\lib

save as *.bat file and run

ref:http://registerboy.pixnet.net/blog/post/24370560-windows7下關於jdk-環境變量-常見問題

2012年7月18日 星期三

Quote: Make bootable usb from bootable cd on Windows

quote from:
http://www.ehow.com/how_5942169_convert-bootable-iso-bootable-usb.html

1

Insert your USB drive into the USB slot in your computer. Open a command prompt window by going through the “Start” menu and searching for “command prompt.” Type “diskpart” into command prompt and press “Enter.” Enter in “list disk” and see what disk number your USB flash drive is. Enter in “select disk #” with # being the disk number of your USB drive. If your USB is disk 3, you would enter in “select disk 3.” Type in “clean” and your USB drive will be erased.


2

Type in “create partition primary” followed by “select partition 1.” Type in “active” and then “format fs=fat32.\" Finally enter in “assign” and type in “exit.” Your USB is now ready to have the ISO put onto it. Copy and paste your bootable ISO file into your USB flash drive. Alternatively, you can mount the ISO file as a virtual drive with Daemon Tools, which is available in the resource section of this guide. Once mounted, open a new command prompt window and enter in “xcopy d:\\*.* /s/e/f e:\\.” The drive letter “d” is the mounted ISO drive and the drive letter “e” is the USB drive. If your ISO is drive X and USB is Y, the command will be “xcopy x:\\*.* /s/e/f y:\\.”


3

Reboot your computer and enter into the BIOS settings by pressing the “F2” button when you see your computer manufacturer’s name. Go to “Boot Options,” and set your USB drive as 1st priority. Press the “F10” button to save your settings, and your computer will reboot from the USB drive.

/dev/sda1 is apparently in use by the system

Possible:

Mount
Umount /dev/sda1

Used by RAID
mdadm -S /dev/md1

2012年7月14日 星期六

2012年7月12日 星期四

Repair bad sector using 'Data Lifeguard Diagnostic for Windows'

Log:
Fast test - OK
Full test - Fail, Bad sector
Write Zeros (Full) - Fail, Bad sector
Write Zeros (Fast) - OK
Write Zeros(Full) - OK
Full test - OK

用Write Zeros (Fast), 再Write Zeros(Full), 再Test


Test Option: EXTENDED TEST
Model Number: WDC WD3200BEVT-75A23T0
Unit Serial Number: WD-WX21A30M8415
Firmware Number: 01.01A01
Capacity: 320.07 GB
SMART Status: PASS
Test Result: FAIL
Test Error Code: 08-Error was detected while repairing bad sectors.
Test Time: 05:23:48, July 11, 2012

Test Option: WRITE ZEROS
Model Number: WDC WD3200BEVT-75A23T0
Unit Serial Number: WD-WX21A30M8415
Firmware Number: 01.01A01
Capacity: 320.07 GB
SMART Status: PASS
Test Result: FAIL
Test Error Code: 09-Sector #25600-25856::Write Zeros error!
Test Time: 05:24:57, July 11, 2012


Test Option: WRITE ZEROS
Model Number: WDC WD3200BEVT-75A23T0
Unit Serial Number: WD-WX21A30M8415
Firmware Number: 01.01A01
Capacity: 320.07 GB
SMART Status: PASS
Test Result: COMPLETE
Test Time: 05:27:06, July 11, 2012


Test Option: WRITE ZEROS
Model Number: WDC WD3200BEVT-75A23T0
Unit Serial Number: WD-WX21A30M8415
Firmware Number: 01.01A01
Capacity: 320.07 GB
SMART Status: PASS
Test Result: COMPLETE
Test Time: 21:22:54, July 11, 2012


Test Option: EXTENDED TEST
Model Number: WDC WD3200BEVT-75A23T0
Unit Serial Number: WD-WX21A30M8415
Firmware Number: 01.01A01
Capacity: 320.07 GB
SMART Status: PASS
Test Result: PASS
Test Time: 05:28:04, July 12, 2012

2012年6月19日 星期二

簡明詞典

價值觀 - 想法與做法 - by Wong Sir
Process scheduling - What process should run on next time and how long
聰明- 做正確的事情, 醒目- 做好一件事 by Tam Sir

2012年6月13日 星期三

mon process via pid file



#!/usr/bin/python3.2
import os

self_pid_path = '/var/run/monPid.pid'
pid_path_list = ['/var/run/mldonkey.pid', '/var/run/sshd.pid']

# olny a instance run

def check_pid(pid):
""" Check For the existence of a unix pid. """
try:
os.kill(pid, 0)
except OSError:
return False
else:
return True

pid_file=None

if os.path.exists(self_pid_path):
with open(self_pid_path, 'r') as oldpid_file:
pid = oldpid_file.readline()
if pid.isdigit() and check_pid(int(pid)):
exit()
else:
pid_file = open(self_pid_path, 'w')
else:
pid_file = open(self_pid_path, 'a')

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

# olny a instance run

# detect mldonkey alive by pid file

for pid_path in pid_path_list:
pid = 0
program = pid_path[pid_path.rfind('/')+1:-4]
if os.path.exists(pid_path):
with open(pid_path, 'r') as pid_file:
pid = pid_file.readline()[:-1]
if pid.isdigit() and check_pid(int(pid)):
print (program + ': alive')
continue
else:
pid = ''

if pid.isdigit() and check_pid(int(pid)):
print (program + '(' + pid + ')' + 'alive')
else:
print (program + '(' + pid + ')' + 'dead')
os.system('echo `date +"%a %b %d %T"` /etc/init.d/' + program + ' restart >> /var/log/monPidFile')



crontab -e
* * * * * /sbin/monPidFile

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