2013年6月13日 星期四

[Linux] 修正 xRDP 遠端登入空白桌面的問題 @ Ubuntu 12.04

xRDP

最近有一台比較有力的機器,主要是安裝 Ubuntu 12.04 Desktop 版,想說趁它還沒那麼忙時,在上頭跑跑 Virtualbox 玩玩,就想到該怎樣使用它的問題,第一個則是遠端登入的方式,試過了 VNC 後,發現一開始沒登入還不能用,所以就改用 xRDP !但登入後卻只能看到一片空白的桌面,於是找了一下解法(Ubuntu 12.10 xrdp gets blank screen at login),筆記一下。

解法:

$ sudo apt-get install xrdp gnome-session-fallback
$ echo "gnome-session --session=gnome" > ~/.xsession
$ sudo vim /etc/xrdp/startwm.sh  (
#. /etc/X11/Xsession
if [ -e $HOME/.xsession ]; then
. $HOME/.xsession
else
. /etc/X11/Xsession
fi
$ sudo /etc/init.d/xrdp restart

此外,如果希望連線過程有加密的效果,可以考慮 ssh tunnel 的用法:

$ ssh -N -L 3389:localhost:3389 remote_server_ip

之後就可以用 RDP 遠端桌面連 localhost 即可

若龜毛一點想要更安全一點,那就用 iptables 擋掉外面來進來 3389,僅允許從 localhost 過來的:

#!/bin/sh

# BIN
BIN_IPTABLES=`which iptables`

# reset rules
$BIN_IPTABLES -F
$BIN_IPTABLES -X
$BIN_IPTABLES -Z

# vnc, rdp: use ssh tunnel

$BIN_IPTABLES -A INPUT -i eth0 -p tcp --dport 5900 -j DROP
$BIN_IPTABLES -A INPUT -i eth0 -p tcp --dport 3389 -j DROP

2013年6月12日 星期三

[Python] Blogger XML Parser @ Mac OS X 10.8.4

最近試了 blogtrans (稍微修改版) 將 PIXNET 網誌備份格式從 MT 轉成 XML 格式,順便研究一下,所以就需要有一支 parser 來處理。


找了一下,在 python 套件中有一套 feedparser 可以使用,十分方便:


$ sudo port install py27-feedparser


用法:


$ ipython
Python 2.7.5 (default, May 28 2013, 22:38:37)
Type "copyright", "credits" or "license" for more information.


IPython 0.13.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.


In [1]: import feedparser


In [2]: xml = feedparser.parse('/tmp/test.xml')


In [3]: xml.entries[0].keys()
Out[3]:
['updated',
 'updated_parsed',
 'published_parsed',
 'tags',
 'title',
 'links',
 'summary',
 'content',
 'guidislink',
 'title_detail',
 'href',
 'link',
 'author',
 'published',
 'authors',
 'author_detail',
 'id']


In [4]: for e in xml.entries:
    ...:      print e.title
    ...:


2013年6月11日 星期二

致我們終將失去的熱情

2013/06/10


青春不再,熱血難耐


最近周邊的情感像極了以前當兵的時候,雖被條款限制在同一艄船上,彼此的方向並不同,隨著船長給予的酒肉短暫狂歡。出了社會後,發現這樣的現象並沒減少反而更加鮮明,同濟之間漸漸地用薪資來衡量未來,似乎年紀增長後,這是回憶起來最不浪費青春的方式吧?盡管現實,但也漸漸地在想自己何時也會掉落到這樣的漩渦呢。


致青春,雖不常在,相繫的可能是生存壓力、往日情感、抑或一丁點的夢想也罷,都該持續珍惜 :)


2013年6月7日 星期五

有感科技業 大陸(上海) VS. 台灣(台北)?



This is Shanghai from Rob Whitworth on Vimeo.

最近跟一位上海 RD 聊了幾句,普遍都說上海在硬體跟消費水平都已超越台灣,說起來大概只剩人文素質或福利相關的部份,聽起來滿感慨的。簡言之,硬體不用說,可以看看影片,消費的話大概比台北貴 30% ,至於人文素質,舉個例就是過馬路要十分小心 XD 據說早期大家出手都很闊,甚至全身穿滿家當,但回家依舊苦哈哈,現況不太清楚,至於暴發戶是政策的關係,例如一胎化導致小孩繼承很多家當,而政府在推動城市時,在都更時用兩間房換一間房的機制,導致換了房後可以收房租過生活,更別說上海被炒起來的價碼,更別說一胎化小孩繼承爸媽、爺奶的房子個數,可能一次就來個 3~4 房呢。

除此之外,這邊要提的則是像機上盒這類科技產業,據在大陸工作 5 年的 RD 分享,台灣了不起就 3000 萬人口,最大咖的就中x電信,最了不起的就 500 萬用戶,在怎樣算也了不起 50 萬台機上盒,在怎樣每年頂多更換 50% 的數量。在大陸隨便一個省就拼過台灣了 Orz 這也就是台灣科技業漸漸也不把台灣放重心的主因,想起來也滿感傷的。

瞧,一年只有 20 萬台的業績,要跟大陸百萬甚至千萬台的量拼,誰會留意台灣啊?

最近在接觸類似機上盒的產業,我發現搞硬體的軟體並非寫的差,倒是因為多了硬體這個維度後,根本沒其他精力去把軟體寫好 Orz 若熟 Web service 的話,應該很清楚只要去把 backend service 、 ui/ux 等的弄好,一切建立在穩當當的 x86 平台,但機上盒底下可能是 MIPS 、可能是 ARM 等類的,一堆應用程式本身都不是為他們設計的,先別說 porting 的痛苦感,連合作硬體穩不穩都是嚴重的問題,還得靠別人家的 SDK 才能生存下去(有沒bug又是另一個故事了),在這樣的環境上,很難會有心力把軟體寫好,或則說,心力都花在搞好硬體上面了

想著想著,覺得從 web service 跨到 embedded 行業,可以有另一層的體驗,那種感覺若要以當紅的 mobile app 來說,那就接近寫 ios app 跟 android app 的差別,在 ios app 硬體環境明確,但 android app 硬體環境不明確,導致在 ios device 上可以有一致的體驗,而 andorid app 很難或要花更多精力才能達成的啊

2013年6月1日 星期六

[PHP] 使用 Heroku 架設 Wordpress 免費部落格


最近大家對 PIXNET 部落格發展方向似乎有不少負面聲音,對我而言倒是還好,但也抽空嘗試其他家服務,其中看到一篇文章:Hosting a WordPress Blog on Heroku with the Svbtle Theme for free ,挺有意思的,就是試了一下。試完的結果是...免費的空間不夠用 XD


根據 Heroku Postgres Basic Plan and Row Limits @ 2012/07/16


Accompanying this announcement is the implementation of a 10,000 row limit on the dev plan. This row limit was designed to correspond to the 5mb limit on the existing free shared plan.


以此 Blog 為例,進行匯入時最後只匯了約 400 篇文章,然後機器就連不到了 XDD:


$ heroku pg:info
=== HEROKU_POSTGRESQL_XXX_URL (DATABASE_URL)
Plan: Dev
Status: available
Connections: 1
PG Version: 9.2.4
Created: 2013-06-01 13:57 UTC
Data Size: 10.4 MB
Tables: 11
Rows: 1584/10000 (In compliance)
Fork/Follow: Unsupported


大概是我比較愛打字 XD 所以使用 Heroku 免費架 Blog 的方案不適合我,但 5MB size & 10000 rows 倒還可以用在其他應用囉 :D


剩下是此次操作方式:


$ git clone git://github.com/webjames/heroku-wordpress-svbtle.git
Cloning into 'heroku-wordpress-svbtle'...
remote: Counting objects: 1447, done.
remote: Compressing objects: 100% (1286/1286), done.
remote: Total 1447 (delta 130), reused 1428 (delta 120)
Receiving objects: 100% (1447/1447), 7.00 MiB | 1.16 MiB/s, done.
Resolving deltas: 100% (130/130), done.


$ cd heroku-wordpress-svbtle


$ heroku create
Creating xxxx-xxx-####... done, stack is cedar
http://xxxx-xxx-####.herokuapp.com/ | git@heroku.com:xxxx-xxx-####.git
Git remote heroku added


$ heroku addons:add heroku-postgresql:dev
Adding heroku-postgresql:dev on xxxx-xxx-####... done, v3 (free)
Attached as HEROKU_POSTGRESQL_RED_URL
Database has been created and is available
! This database is empty. If upgrading, you can transfer
! data from another database with pgbackups:restore.
Use `heroku addons:docs heroku-postgresql:dev` to view documentation.


$ heroku pg:promote HEROKU_POSTGRESQL_RED
Promoting HEROKU_POSTGRESQL_RED_URL to DATABASE_URL... done


$ git checkout -b production
Switched to a new branch 'production'


$ cp wp-config-sample.php wp-config.php
$ >.gitignore
$ git add .
$ git commit -m "Initial WordPress commit"
[production #######] Initial WordPress commit
2 files changed, 93 insertions(+)
create mode 100644 .gitignore
create mode 100755 wp-config.php


$ git push heroku production:master
Counting objects: 1450, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1278/1278), done.
Writing objects: 100% (1450/1450), 7.00 MiB | 173 KiB/s, done.
Total 1450 (delta 132), reused 1445 (delta 130)


-----> PHP app detected
-----> Bundling Apache version 2.2.22
-----> Bundling PHP version 5.3.10
-----> Discovering process types
Procfile declares types -> (none)
Default types for PHP -> web


-----> Compiled slug size: 16.0MB
-----> Launching... done, v6
http://xxxx-xxx-####.herokuapp.com deployed to Heroku


To git@heroku.com:xxxx-xxx-####.git
* [new branch] production -> master


其他部分:


將 Wordpress 設定為必須登入才能看到文章:


$ cat wp-blog-header.php
<?php
/**
* Loads the WordPress environment and template.
*
* @package WordPress
*/
if ( !isset($wp_did_header) ) {


  $wp_did_header = true;


  require_once( dirname(__FILE__) . '/wp-load.php' );


  if ( !is_user_logged_in() ) {   // 太久沒用 wordpress ,印象中有選項可以設定:限定登入才能看到文章
    auth_redirect();
    exit;
  }


  wp();


  require_once( ABSPATH . WPINC . '/template-loader.php' );


}


啟用 MT 匯入功能:


$ wget -qO- http://downloads.wordpress.org/plugin/movabletype-importer.zip | tar -xvf - -C wp-content/plugins/
$ git add .
$ git commit -am 'add movabletype-importer plugin'
$ git push heroku production:master


由於 heroku 僅能上傳 2MB 大小的檔案,若你的 Blog 之 MT 備份檔超過 2MB 的話,可以擺在 blog site 匯入。


$ cp /path/you_blog_backup.txt wp-content/mt-export.txt
$ git add .
$ git commit -am 'add mt-export.txt'
$ git push heroku production:master


接著就可以去後台管理來匯入資料。