網頁

2013年6月6日 星期四

Ubuntu 安裝 Sublime Text 2與中文輸入問題

2013/12/04註: Sublime Text 3 beta在2013/06/27已開放給未註冊使用者下載

為了要能垂直編輯多行文字,在特定時候,只留下或編輯多行文字中的值,所以要裝sublime來用看看。
像是以下資料:
  * PID: 7234
  * PID: 6821  
  * PID: 7108    
可以按Ctrl-Alt + 上下左右,選取範圍後,删除或編輯。
變成像是:

  * 7234
  * 6821
  * 7108

即使位置不對等或不是連續,例如:
style="width: 500px;"
style="height: 100px; width: 50px;"
style="width: 80px;"

可以按Ctrl +滑鼠左鍵,點選要插入資料的位置,就可加入相同的內容到各個地方。
style="width: 500px; color: red;"
style="height: 100px; width: 50px; color: red;"
style="width: 80px; color: red;"

目前無法使用apt-get 來安裝,安裝方式如下:
  1. 先下載Linux 32或64於http://www.sublimetext.com/2.
  2. 開啟Terminal.
  3. cd ~/下載
  4. tar -xf "Sublime Text 2.0.1 x64.tar.bz2"  (檔名依下載版本修改)
  5. sudo mv "Sublime Text 2" /usr/lib
  6. sudo ln -s "/usr/lib/Sublime Text 2/sublime_text" /usr/bin/st2
啟動方式一:
  • Terminal中輸入st2
    • # st2
啟動方式二:
  • 加入左邊的啟動器選單中
    • 先在dash中找“主選單” ,接著按“新增項目”,加入/usr/bin/st2.
    • 然後在dash中就可找到 Sublime Text 2,並拉到啟動器。

參考:http://www.arthurtoday.com/2012/09/ubuntu-install-sublime-text-2.html

2013/06/20補充,無法輸入中文的解決方法:
在windows和linux(搭配ibus; scim;fcitx)都有不同狀況的無法輸入中文,
這裡只針對環境ubuntu+ibus,可以安裝plugin來解決。
安裝一個sublime text 2的插件InputHelper,用於輸入中文,安裝如下:
cd ~/.config/sublime-text-2/Packages 
git clone https:// github.com/xgenvn/Input Helper.git
重新啟動之後按Ctrl+Shift+Z可跳出一個中文輸入框(不好用但加減用)。

2013年4月26日 星期五

Copy a file to multiple directory.

Copy a file to multiple folder. Can use find command and type directory (-type d). 
Then use -exec run cp command copy to target {}.

e.g.
find . -name "folder_name" -type d -exec cp /xxx/filename.txt {} \;

2013年3月29日 星期五

Set user shell using ssh script to linux base system and sudo problem.

I using ruby ssh library to linux server. then run sudo command.
like "sudo usermod -s /sbin/nologin Chien-Ming-Wang".


centos:
  Set user shell: sudo chsh -s /sbin/nologin [login name]
  When error: "sudo: sorry, you must have a tty to run sudo"
    vi /etc/sudoers
    mark line: "Defaults    requiretty"


Debian & Ubuntu:
  Set user shell: usermod -s /usr/sbin/nologin [login name]
  When error: "sudo: no tty present and no askpass program specified"
    vi /etc/sudoers
    Add line: [login name] ALL=(ALL) NOPASSWD: ALL

FreeBSD:
  Set user shell: sudo pw usermod [login name] -s /usr/sbin/nologin
  When error: "sudo: no tty present and no askpass program specified"
    vi /usr/local/etc/sudoers
    Add line: [login name] ALL=(ALL) NOPASSWD: ALL

2013年3月18日 星期一

用ssh tunnel來突破公司的防火牆

用ssh tunnel來突破公司的防火牆

外部電腦能連至Server,但Server不能連至公司內電腦,但公司內電腦能連至Server,此時運用反向Tunnel。

  • 公司內電腦建立反向Tunnel連至Server: ssh -NfR 2222:127.0.0.1:22 server_ip_or_domain
  • 外部電腦建tunnel連至Server: ssh -NfL 4444:localhost:2222  server_ip_or_domain
  • 外部電腦 即可連至公司內電腦:  ssh -p4444 localhost


外部電腦不能連至公司內電腦,但內部電腦能連至外部電腦,此時運用反向Tunnel。

  • 公司內電腦建立反向Tunnel連至外部電腦 ssh -NfR 2222:127.0.0.1:22 external_ip_or_domain
  • 外部電腦 即可連至公司內電腦:  ssh -p2222 localhost

參數說明
  • -L [bind_address:]port:host:hostport
    • Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.
  • -R [bind_address:]port:host:hostport
    • Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side.
  • -N      Do not execute a remote command. 
  • -f      Requests ssh to go to background just before command execution.



2012年4月6日 星期五

Working with Unicode in Ruby

ruby的irb中要顯示中文
輸入
irb> $KCODE = 'u'
就可以了

其它處理utf8字串的有
irb> require 'jcode'
irb> require 'rubygems'
irb> require 'unicode'

詳細參考 http://ideaharbor.org/notes/technical/working-with-unicode-in-ruby

2012年3月1日 星期四

wiki markup convert

使用Perl HTML-WikiConverter
安裝參考:http://cpan.uwinnipeg.ca/htdocs/HTML-WikiConverter/INSTALL.html
完整安裝:

% perl -MCPAN -e 'install Bundle::HTMLWikiConverter'

部份安裝:

cd /usr/ports/lang/perl5.8; make install clean
perl -MCPAN -e 'install HTML::WikiConverter'
perl -MCPAN -e 'install HTML::WikiConverter::MediaWiki'


轉換程式參考 http://en.wikipedia.org/wiki/Help:WordToWiki
mkdir convert_wiki; cd convert_wiki
vim convert.pl <- 貼入程式

#!/usr/bin/perl
# html2mw - HTML to MediaWiki converter

use HTML::WikiConverter;

my $b;
while (<>) { $b .= $_; }

my $w = new HTML::WikiConverter( dialect => 'MediaWiki' );

my $p = $w->html2wiki($b);

# Substitutions to get rid of nasty things we don't need
$p =~ s/
//g;
$p =~ s/\ \;//g;
print $p;


vim wiki_page.html <- 貼入要轉wiki的html

test


test




perl convert.pl wiki_page.html
就出現轉換的結果。

=test=

==test==

[Perl] 解決 Wide character in print with UTF-8 mode

print 出中文資料會出現 “Wide character in print at” 的 warning 訊息
解決方法在表頭加上以下。

use utf8;
binmode(STDIN, ':encoding(utf8)');
binmode(STDOUT, ':encoding(utf8)');
binmode(STDERR, ':encoding(utf8)');