2013年6月24日 星期一

日文促音(小字)怎麼打


在前面加上x 或 l (little)

っ (ltu, xtu)
ゃ (lya, xya)
ゅ (lyu, xyu)
ょ (lyo, xyo)

ー (注音ㄦ鍵)

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
$ 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 網路的共用接口


# 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                                                               
{
    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;
    };
};
# /etc/init.d/radvd restart

# 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)
// 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 - 班傑明的奇幻之旅- 點部落
網際網路通訊協定升級推動方案

PHP detect client browser and OS



Reference :
php - Browser and OS detection script - Code Review Stack Exchange


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


2013年6月11日 星期二

Linux Debian Firefox 21 安裝 Adobe Flash Player 11

下載 .tar.gz for other Linux,存到 /tmp


安裝步驟:
$ 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

debian / ubuntu 7z



# apt-get install p7zip
 

$ 7zr x myfiles.7z

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

PHP File Upload Error Codes explain





Reference :
PHP File Upload Error Codes; UPLOAD_ERR_OK « Dark Launch

2013年6月9日 星期日

No module named gdata.spreadsheet.service

Download :

gdata-python-client - Google Data APIs Python Client Library - Google Project Hosting

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"

ValueError: time data '23/Nov/2012:11:15:44' does not match format '%d/%b/%Y:%H:%M:%S'

$ LC_ALL=C python
or
import locale

locale.setlocale(locale.LC_TIME, "C")





Reference :
datetime - Python: date formatted with %x (locale) is not as expected - Stack Overflow

ImportError: No module named Crypto

# pip install crypto

ImportError: No module named pbkdf2

# pip install pbkdf2

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月6日 星期四

Python switch case

PHP :
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月4日 星期二

Python Bottle 操作 MySQL 的幾種方式

1. bottle_mysql plugin

需寫 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