2013年6月25日 星期二
Bottle SimpleTemplate Engine if... else... condition
{{ 'checked' if (user.activited == 1) else '' }}
Reference :
python - handling undefined values in bottle's SimpleTemplate Engine templates - Stack Overflow
2013年6月24日 星期一
2013年6月19日 星期三
Python check if string is JSON format
def isJSON(s):
import json
try:
json_object = json.loads(s)
except ValueError, e:
# invalid json
return False
else:
# valid json
return True
2013年6月18日 星期二
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
在套件庫端設定
$ git config receive.denyCurrentBranch ignore
or
$ git config --global receive.denyCurrentBranch ignore
Linux 使用 sshfs 連結 Android 4.0
Android :
(WIFI 順暢狀態)
安裝 SSHelper
啟動後會監聽在 WIFI 界面上
Username : root
Password : admin
Post : 2222
Linux :
// mount
(WIFI 順暢狀態)
安裝 SSHelper
啟動後會監聽在 WIFI 界面上
Username : root
Password : admin
Post : 2222
Linux :
// mount
$ sshfs -o port=2222,idmap=user,uid=1000,gid=1000 root@192.168.99.100:/ ./Your_SmartPhone_Mount_Point// umount
$ fusermount -u ./Your_SmartPhone_Mount_Point
2013年6月14日 星期五
Xen with IPv6
請先確認 Dom0 已經建立好 IPv6 連線
Dom0 :
已建立好與 Server 連接的端點 (sit0、sit1),另外有另外可以使用的網段,把他設定在 DomU 網路的共用接口
DomU :
Dom0 :
已建立好與 Server 連接的端點 (sit0、sit1),另外有另外可以使用的網段,把他設定在 DomU 網路的共用接口
# ifconfig eth0 inet6 add 2001:470:f902::1/48
// radvd - Router Advertisement Daemon
# apt-get install radvd
# vi /etc/radvd.conf
interface eth0 #The interface used to send ADV# /etc/init.d/radvd restart
{
AdvSendAdvert on; #Enable Advertisements
#AdvManagedFlag on; #Enable Managed bit
#AdvOtherConfigFlag on; #Enable Other Configure bit
MinRtrAdvInterval 3; #Set min. interval to send adv.
MaxRtrAdvInterval 10; #Set max. interval to send adv.
prefix 2001:470:f902::/48 #Prefix
{
AdvOnLink on; #Adv. Using Link Layer
AdvAutonomous on; #Autonomous Flag
#AdvRouterAddr on;
};
};# echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
DomU :
# ifconfig eth0 inet6 add 2001:470:f902::2/48
# route -A inet6 add ::/0 dev eth0
# route -A inet6 // show ipv6 route
$ ping6 2001:470:f902::2/48 // gateway
$ ping6 2600::
Connect to IPv6 Broker on Linux
1. Register a IPv6 Tunnel Broker
2. Create Tunnel (auto)
3. Create Tunnel (manual)
4. Test
* Not starting gogoc – no server key
Ubuntu 10.10 Marverick 使用gogoc替代gw6c连接IPv6 | 谢邵虎博客
Reference :
[Linux] 使用 hinet IPv6 的服務 | richliu's blog
[筆記]IPv6超簡單實作--Tunnel Broker - 班傑明的奇幻之旅- 點部落
網際網路通訊協定升級推動方案
2. Create Tunnel (auto)
// gw6c
// gogoc - Client to connect to IPv6 tunnel brokers
# apt-get install gogoc
# vi /etc/gogoc/gogoc.conf
31 userid=YOUR_USERID
32 passwd=YOUR_PASSWORD
54 server=Tunnel_Server_IPv4_Address
73 auth_method=any
# /etc/init.d/gogoc restart
# ifconfig tun
3. Create Tunnel (manual)
Choose Server |
Tunnel Details |
Example Configurations |
4. Test
$ ping6 ping6 2600:: // the shortest available IPv6 address
http://ipv6.google.com/
* Not starting gogoc – no server key
Ubuntu 10.10 Marverick 使用gogoc替代gw6c连接IPv6 | 谢邵虎博客
Reference :
[Linux] 使用 hinet IPv6 的服務 | richliu's blog
[筆記]IPv6超簡單實作--Tunnel Broker - 班傑明的奇幻之旅- 點部落
網際網路通訊協定升級推動方案
2013年6月13日 星期四
Install PlayOnLinux in Debian
# apt-get install playonlinux p7zip-full ttf-mscorefonts-installer
Reference :
Downloads - PlayOnLinux - Run your Windows applications on Linux easily!
Reference :
Downloads - PlayOnLinux - Run your Windows applications on Linux easily!
2013年6月12日 星期三
forward vnc to rdp(3389) using xrdp
// 安裝
# apt-get install tightvncserver
# apt-get install xrdp
// 啟動 vncserver
$ vncserver -geometry 1024x768 // it will set password
// 連結 RDP
$ rdesktop localhost
# apt-get install tightvncserver
# apt-get install xrdp
// 啟動 vncserver
$ vncserver -geometry 1024x768 // it will set password
// 連結 RDP
$ rdesktop localhost
2013年6月11日 星期二
Linux Debian Firefox 21 安裝 Adobe Flash Player 11
下載 .tar.gz for other Linux,存到 /tmp
安裝步驟:
Reference :
管理 Flash 外掛程式(plugin) | Firefox 說明
安裝步驟:
$ cd /tmp
$ tar zxf install_flash_player_11_linux.i386.tar.gz
$ mkdir ~/.mozilla/plugins/
$ cp libflashplayer.so ~/.mozilla/plugins/
Reference :
管理 Flash 外掛程式(plugin) | Firefox 說明
Python Bottle Authentication
Basic Authentication in bottle.py
Fledgling Polymath — Basic Authentication in bottle.py
Bottle Extended Module
Cork - Authentication for the Bottle web framework — Cork 0.5 documentation
Bottle, Cork & MongoDb adventure – Peter Bruinsma
Windows PHP scandir() 中文 亂碼
$filelist = @scandir($UPLOAD_PATH);
// remove dir '.' , '..'
unset($filelist[0]);
unset($filelist[1]);
if($filelist)
{
if(PHP_OS == "WINNT")
{
foreach($filelist as $key => $value)
{
$filelist[$key] = mb_convert_encoding($value, "UTF-8", "big5");
}
}
}
php get server os
echo PHP_OS;
Reference :
PHP script - detect whether running under linux or Windows? - Stack Overflow
2013年6月10日 星期一
2013年6月9日 星期日
Linux screen brightness / backlight
$ xrandr --output LVDS1 --brightness 0.9
bmark -title="Kernel/Debugging/Backlight - Ubuntu Wiki" https://wiki.ubuntu.com/Kernel/Debugging/Backlight
bmark -title="Unable to change brightness in Lenovo B570 laptop" http://ubuntuforums.org/showthread.php?t=1827810
bmark -title="Backlight - ArchWiki" https://wiki.archlinux.org/index.php/Backlight
bmark -title="How to change brightness on linux desktop through the command line? - Super User" http://superuser.com/questions/256084/how-to-change-brightness-on-linux-desktop-through-the-command-line
vbmark -title="opensuse - How to change the Monitor brightness on Linux? - Stack Overflow" http://stackoverflow.com/questions/6625836/how-to-change-the-monitor-brightness-on-linux
xbacklight No outputs have backlight property
Not xbacklight's fault.
xserver-xorg-video-intel used to offer a few methods for changing the
backlight, defaulting to platform drivers providing
/sys/class/backlight/*. With KMS the i915 driver should probably
provide a fallback if there's no platform driver for backlight.
Reference :
Answer : Bug#569892: xbacklight: after having worked before, now just prints "No outputs have backlight property"
xserver-xorg-video-intel used to offer a few methods for changing the
backlight, defaulting to platform drivers providing
/sys/class/backlight/*. With KMS the i915 driver should probably
provide a fallback if there's no platform driver for backlight.
Reference :
Answer : Bug#569892: xbacklight: after having worked before, now just prints "No outputs have backlight property"
ValueError: time data '23/Nov/2012:11:15:44' does not match format '%d/%b/%Y:%H:%M:%S'
$ LC_ALL=C pythonor
import locale
locale.setlocale(locale.LC_TIME, "C")
Reference :
datetime - Python: date formatted with %x (locale) is not as expected - Stack Overflow
Fatal error: Python.h: No such file or Directory
# apt-get install python-dev
Reference :
Debian / Ubuntu: Fatal error: Python.h: No such file or Directory
2013年6月7日 星期五
Python global variable between modules / classes / files
import __builtin__
__builtin__.myShareVar = 'abcd1234'
__builtin__.myShareVar = 'abcd1234'
wget https ERROR: The certificate of '*' is not trusted.
$ wget --no-check-certificate https://example.com/testfile.tgz
2013年6月6日 星期四
Python switch case
PHP :
Python :
Reference :
Python的switch…case语法 | vifix.cn
switch(lang)
{
case 'zh':
zhDo(argu);
break;
case 'jp':
jpDo(argu);
break;
default:
enDo(argu);
break;
}
Python :
try:
{
'zh': zhDo,
'jp': jpDo,
}[lang](argu)
except KeyError:
# default action
enDo
Reference :
Python的switch…case语法 | vifix.cn
2013年6月5日 星期三
2013年6月4日 星期二
Python Bottle 操作 MySQL 的幾種方式
1. bottle_mysql plugin
需寫 SQL 語句
需透過 bottle route 傳入 db 連結句柄,靈活度不高
bottle-mysql 0.1.1 : Python Package Index
2. 自己封裝 MySQLdb 類別
需寫 SQL 語句
function 可重用
bottle-linkshorter/linkshorter.py at master · denschub/bottle-linkshorter · GitHub
3.使用 ORM
需要定義每個表格、欄位資訊
功能較強大 (基本功能不需寫 SQL 語句、資料欄位驗証、安全過濾)
CURD.py | Tiny Python ORM for MySQL — CURD.py | Tiny Python ORM for MySQL
SQLAlchemy - The Database Toolkit for Python (powerful)
Reference :
What are some good Python ORM solutions? - Stack Overflow
需寫 SQL 語句
需透過 bottle route 傳入 db 連結句柄,靈活度不高
bottle-mysql 0.1.1 : Python Package Index
app = default_app()
db_plugin = mysql.Plugin(dbhost=DB_HOST, dbuser=DB_USER, dbpass=DB_PASS, dbname=DB_NAME, keyword='db') # default keyword is db
app.install(db_plugin)
2. 自己封裝 MySQLdb 類別
需寫 SQL 語句
function 可重用
bottle-linkshorter/linkshorter.py at master · denschub/bottle-linkshorter · GitHub
3.使用 ORM
需要定義每個表格、欄位資訊
功能較強大 (基本功能不需寫 SQL 語句、資料欄位驗証、安全過濾)
CURD.py | Tiny Python ORM for MySQL — CURD.py | Tiny Python ORM for MySQL
SQLAlchemy - The Database Toolkit for Python (powerful)
Reference :
What are some good Python ORM solutions? - Stack Overflow
2013年6月3日 星期一
Python MySQLdb query results with column name
conn = MySQLdb.Connect( host='localhost', user='root', passwd='', db='test',compress=1, cursorclass=MySQLdb.cursors.DictCursor)or
cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
Reference :
MySQL and accessing database results by field « Python recipes « ActiveState Code
Python auto import module from sub directory
import sys
sys.path.append('/your/module/directory')
from autoimp import *
your_module.test()
Some keywords :
import imp
imp.load_module
module = __import__("module")
globals().update(vars(module))
Reference :
python - When automatically importing modules from a subfolder, their imports fail - Stack Overflow
Some Notes on Importing Modules by Name
python - Dynamic importing of modules followed by instantiation of objects with a certain baseclass from said modules - Stack Overflow
Some Notes on Importing Modules by Name
python - Dynamic importing of modules followed by instantiation of objects with a certain baseclass from said modules - Stack Overflow
Python autoimp module
2013年6月2日 星期日
訂閱:
文章 (Atom)