Wednesday, October 11, 2023

敵人 Enemy

在戰區的朋友今天傳來消息,她家裡一位行動不便的人來不及逃亡,被炸死了。

九二一地震時,也有許多人自己逃得了,但眼睜睜看著慢一步的親人罹難。這種痛,除了失去親人外,還加上倖存者的罪惡感。

而戰爭帶來的苦難,又比天災更進一步:天地不仁,帶來災難,人類也只能面對;但戰爭卻是人為的,是某些人覺得自己某些利益比他人的生命更寶貴,而覺得可以犧牲他人生命。這種痛,又更上一層。


很多人生日許願時常說要祈求世界和平,好像真的有一位專管生日許願的神,來應允每個人的三個願望。我沒聽過有這樣的神。

生日許願,不應像求阿拉丁神燈,求完了就沒自己事了;而應像新年立願一樣,當做是自己努力的目標。

真想要世界和平,至少先把自己與他人的關係弄好,想辦法減少自己外在的敵人與內在的敵意。


朋友痛失家人生命的離去,我立願以減少自己暴戾之氣作為新生命的開始。


Tuesday, April 30, 2019

Streaming Custom Videos in Google Hangouts

Summary:

With this method, I was able to send Google Hangouts any video contents, such as me with a news broadcast background, while the small TV in that background is showing my desktop playing a live Youtube video.

Update: now there's an easier way: use OBS's v4l2sink plugin + v4l2loopback kernel module. See this article.


OBS is a fine tool that enables us to overlay various visual/audio sources, on the fly, for streaming and/or recording. Unfortunately, it doesn't support a virtual cam under Linux (there is a plugin that only works under Windows), i.e. I can't send a complex composition of a live desktop screen, webcam, video, etc. to Google Hangouts.

Webcamoid is another fine tool that supports output to a virtual cam under Linux, which Google Hangouts can directly use.

Several attempts were made, but I wasn't able to get a result with low enough latency for video conferencing. The video latency caused an unacceptable out-of-sync problem with the audio.

I reached an easy workaround, which is resource heavy, but works quite well.
  1. Use OBS to construct the target scene, say, a chroma keyed webcam, with a video background, and a logo foreground, as well as a live chat overlay.
  2. In OBS, right click on the preview, and project it under a separate screen.
  3. In Webcamoid, choose that screen as the source.
  4. In Google Hangouts, choose Webcamoid's virtual cam instead of the real webcam.
  5. Voila! Now I have full control of what others see in my video conferencing.
This solution needs one whole screen just to link OBS and webcamoid. Any of the following improvement of either project will make this workflow even better:
Hopefully either will come soon.

Friday, October 13, 2017

uwsgi wrong python interpreter

In some projects, I use uwsgi behind nginx to drive Django. I also use virtualenv to manage my environments (by the way, Panda's introducing .ix and then deprecating it wasn't fun). In a recent update, I was pulling my hair out trying to figure out why I'm getting the following error message, and a wrong Python interpreter.


Could not find platform independent libraries
Could not find platform dependent libraries
Consider setting $PYTHONHOME to [:]
Python version: 3.5.4 |Continuum Analytics, Inc.| (default, Aug 14 2017, 13:26:58)  [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
Set PythonHome to /opt/anaconda
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'



It turned out that the problem was in the binary code of uwsgi in my environment. It was compiled for another environment, with the environment path hard-coded in. Yes, in the binary. I had done that in another environment and the compiled package stayed in the pip cache, and the new environment just picked it up from the cache, causing inconsistency!

The solution:


pip install --no-cache uwsgi

Tuesday, July 11, 2017

Ergodox EZ Configurator Layer Manipulation

Ergodox EZ provides a great configurator; however, it doesn't provide all editing functions I need. Unfortunately, the source code disappeared from github (multiple unofficial documents have links to that repo so I assume the source was once available; this is rather disappointing, since the company made it look like that they are using all open source resources.)

One of the functions that I need the most is swapping the layers.

Here's what I did to achieve it:

Upon examining the minimized javascript, it was written against the React framework. Therefore, I installed the React debugger extension for chrome, in order to find and manipulate the variable that stores the layer information.

Once the extension is installed, reload the page, and open up the Developer Tools in Chrome.
Click on React to open the debugging panel.
Make sure the correct scope "App" is selected.
Now the variable $r will contain the React object, including the state, for editing.
The layers (including all key assignment) information is in the array: $r.state.layout.layers

Here's an example of swapping layer 3 and 4.


$r.state.layout.layers = [
$r.state.layout.layers[0],
$r.state.layout.layers[1],
$r.state.layout.layers[2],
$r.state.layout.layers[4],
$r.state.layout.layers[3],
$r.state.layout.layers[5],
$r.state.layout.layers[6],
$r.state.layout.layers[7],
]



Note that if there are layer switching keys, you'll also need to manually modify those from the GUI.

I also did some batch editing offline, and then re-assign the whole $r.state.layout.layers
by first converting the variable to JSON and write it to a local file, with this snippet.

Also when you copy/create a layer, make sure to use the GUI to first allocate the variable $r.state.layout.layers[x].keyboard_layout_id on their server and then carefully copy those values.

Here's my current setup, if you are interested.



Saturday, February 6, 2016

Fixing Lenovo U31-70 WiFi Problem

Abstract

Lenovo U31-70 is a lightweight laptop. Its WiFi performance has been a headache to many people. Most people report unstable signal dropping.

For those who use Windows and are experiencing unstable WiFi problem, you just need to solve the hardware problem.

I use Linux, so I had to go a different route to solve my driver problem.

The Hardware Problem

I opened up the laptop, and found that the two antenna cables were not properly attached to the card. There was a tape (not shown in the picture) trying to keep the two cables attached, but failed due to the tension from the bending; also, the screw to attach the card onto the main board is too close to one of the antenna contacts so it automatically grounds it, making that antenna useless. This is a design problem.



I first re-attached the two cables back to their contacts and re-tape them, and put some non-conductive material between the screw and the contact to prevent the grounding. It helped.

The Atheros 10K Driver Problem under Linux

I had used several Thinkpads since its IBM days, so I was quite surprised to have found that this Lenovo's Atheros 10K chip was not supported under Linux. People were reporting stable driver performance under Windows, and some efforts were made to bring the firmware from Windows driver to Linux. I waited a few months for Linux kernel to come to version 4.3 and spent a lot of time trying various hacks to get the driver working. I was never able to get stable performance.

I decided to replace the card with Intel Dual Band Wireless AC 3160, which is well supported by native Linux.

(I have no idea which antenna cable is intended for WiFi and which is for bluetooth, but this works for me; besides, tension-wise, this is the only way I could keep the contacts isolated.)

It has been working flawlessly.


Saturday, January 30, 2016

Coordinate Transformation Matrix for Touchscreen in multi-screen setup in X11

Currently I have a twin screen setup in Arch Linux, like this:

On the left, DELL 1901FP is turned 90 degree counter-clockwise in its portrait mode. On the right, DELL P2314T, a touch screen, is in its regular landscape orientation, with its bottom line aligning with the bottom of the rotated screen on the left.

Here's my xorg.conf for that. (Although one can also setup screen arrangement in KDE/Plasma/Gnome/etc., for KDM/SDDM/GDM/etc. to recognize it in the login screen, it's important to put this in xorg.conf)





X11 sees a (1024+1920) wide * 1280 high DISPLAY, with an upper-right corner being invisible.

Since the touchscreen is just a regular pointer device (through its driver), when I put my finger on the left border of the touchscreen on the right, the cursor goes all the way to the very left of the DISPLAY. Touchscreen is only useful if the cursor follows my finger. Therefore, we need to do some Input Coordinate Transformation.

Coordinate Transformation Matrix is precisely the needed configuration.

From the documentation above, our goal is to map the following coordinates on the left (X11's default behavior) to the ones on the right:



So that means we are solving the following system:


Here's the solution:

Convert it to float numbers:

Now we can put these numbers into the configuration, as the document instructed.





However, it doesn't work. The cursor stays on the lower right. After some debugging, I found the offsets 1024 and 200 were the culprit. They need to be a percentage, i.e. relative to the full width and height.

So 1024.0/(1024+1929) = .3476766, 200.0/1280 = .15625





I put it in /usr/share/sddm/scripts/Xsetup (or /usr/share/config/kdm/Xsetup if you haven't upgraded to plasma) as well as ~/.xprofile so it automatically runs every time.

Edit 2016-02-22: I ended up having 3 screens with two in the portrait orientation. SDDM correctly uses metamodes setting in xorg.conf, regardless of the screen power. However, KDE is more sensitive to that so sometimes the layout is messed up. Here's a script to quickly correct that.




Monday, October 19, 2015

Install Sibelius 8.0.1 on a non-C drive in Windows

Since Sibelius 8.0.0, Avid changed the installer, and it has a serious bug -- it assumes you have a C: drive before letting you choose the installation destination. I figured out a hack to install it. However, it doesn't work for Sibelius 8.0.1, so here's another way to approach it, before Avid's Sibelius team fixes the bug.

I don't have a C: drive, but Sibelius insists that I must do, so what we are trying to do here is to temporarily create a C: drive, and then create a link pointing crucial directories back to my system drive, K:. After Sibelius is successfully installed, we can then safely remove the temporary C: drive.

First, we need to create a Virtual Hard Drive (VHD) as our C:\ drive. I learned how to do this via this answer:
  • Start → run → diskmgmt.msc (accept all defaults... I'm not doing anything special below) 
  • From the menu bar select Action → Create VHD 
  • Choose the location and name the file (which will be the vhd) and specify the size and click OK. My file is K:\virtual_drive_c.vhd and the size is 1G, but I made it dynamic so it's actual size is around 16MB. 
  • Right click on the Disk # (underneath will be Unknown and the size and "Not Initialized"). Select "Initialize Disk" and click OK 
  • Right click on the black bar of the unallocated disk space and select "new simple volume". A wizard opens up an on the second page it lets you assign the drive letter. We want C: here. Complete the wizard and you're done!
Now that we have a C: drive, we can link the important folders. I learned how to do that from this post:
  • Start → run → cmd, then right click and choose "Run as Administrator". 
  • In the prompt, type the following:
K:\>mklink /j "C:\Program Files" "K:\Program Files"
Junction created for C:\Program Files <<===>> K:\Program Files

K:\>mklink /j "C:\Program Files (x86)" "K:\Program Files (x86)"
Junction created for C:\Program Files (x86) <<===>> K:\Program Files (x86)



After that, Sibelius installation should run normally. In the installer, I still choose to install the program to K:, to avoid future problems running Sibelius, since the bug is on the installer, not Sibelius itself.

Afterwards, you can reboot, and safely delete the vhd file.

Thursday, September 24, 2015

大易二十七年,行列二十七小時

綱要

我打大易輸入法很快,甚至比一些人用講的還快,但最近考慮換到行列輸入法。

我學大易輸入法的歷史

我小學正是Apple II電腦剛進入台灣的時候。那時候Apple II能插一張「佳佳漢卡」來顯示中文。打字方面只有倉頡與注音。我試學了幾次倉頡,最後都放棄。主要也因為那時候打中文的機會少,所以茍且用注音好多年。

注音很好學,但因為中文同音字太多,選字鍵就只那一排數字鍵,導至最後總鍵數高,輸入速度大大受限。

高一時做科展,要寫一堆文字報告。那時我字寫得難看,於是決定趁機把中打好好學。剛好大易輸入法剛出來,在雜誌上廣告,看到後就決定去他們公司問問看。下課後拎了書包就搭了公車去太易公司在中山北路(?)的辦公室。那時好像只有三位員工。其中一位先生看到高中生想學大易,很興奮。49元賣了我一本原價99的書,給我一疊字根卡,希望我回班上幫忙推廣。

大易的優點

大易說真的很了不起。讓我一個晚上就能把規則學完,看字根表打字。一星期內就完全不需要字根表了。我成功的例子也讓身邊很多人學大易用大易至今。那位先生應該覺得很欣慰。:)

用了二十七年的大易,打字速度其實蠻快的,有幾個朋友應該看過我打字追上一些人講話的速度。

我覺得大易的設計很好,字根的分類很直覺。基本上看到字就知道怎麼拆。其實,中文打多了,大部份人應該看到字就直接能跳過拆碼,直接以手指記憶打出來。

另外一個大優點是字根與字鍵的分布很平均,所以在常用字裡,需要選字的機會其實不多。

一些常見輸入法的問題

倉頡難學。字鍵數也偏多。

注音的問題上面提過,即使有些朋友熟到連選字鍵選字頁都一起背了起來,總鍵數還是太多,容易疲勞。

現在有很多智慧型輸入法,可以自動選字,或自動選詞,速度很快。但我對打字的需求比較傳統:我需要能夠完全預測什麼鍵會出什麼字。也就是說,我需要不用看瑩幕就能正確地打字。這樣能讓我做筆記時,眼睛不需要去顧打字窗。不管在做筆記或是創作,選字會讓我分心。我覺得這和演奏樂器的原理一樣,一個音彈拉吹敲下去,音高、音色、強弱都應該要能精確預期。

還有這些輸入法大多以詞為單位來做智慧選擇。字詞的頻率在不同軟體版本中會有出入,造成可預測性降低。

大易的缺點

版權的問題

大易的版權並非完全自由,許多自由軟體無法直接包含大易。網路上流通的合法版本是太易公司多年前釋出的,字數有限。後來雖然有許多熱心人士擴充,但也造成版本間有出入的問題。

平台的問題

我常用的作業系統有五個:Linux為主,手機Android,筆記型電腦是OSX,音樂的工作用Windows,以及平版的iOS。各個平台共通內建的繁體中文輸入法,只有注音與倉頡。(其他輸入法有的名稱相同,內容卻不統一)

由於上述的版權問題,軟體無法直接包含大易,所以這個過程只能手動。雖然花點力氣,也能把大易都裝上去(gcin, Lime, Open vanilla, 內建, JB/iAccess),但辛苦的是,每次系統或是作業環境升級,這個過程就得重來一次。

選字鍵的問題

大易的選字鍵和其他輸入法不同。大部份輸入法用上排數字鍵來選字,但大易把上排數字鍵和英文字母鍵都拿來當字根。這個設計,有效地讓總鍵數及選字的頻率都大大減少。但使用非標準選字鍵的缺點是,軟體必須特別設計來支援大易。隨著其他智慧型輸入法普及後,大易的使用族群變為少數,願意為大易特別設計的軟體就變少了。

可能的解決方案

最近發現令人驚艷的「瑲珩--動態拆碼暨動態組字」計畫,也許能解決版權、版本及字數的問題。

但平台的問題,卻是我目前面臨的挑戰。比方說,gcin是很優秀的程式,但在Chromium或是Qt升級間常常造成不相容(問題不一定是gcin本身)。雖然問題總會解決,但發生的頻率高到太不方便。

我考慮用iBus之類較普及的平台,看與其他軟體的相容性會不會好一點。選了軟體後,也要找大部份軟體都支援的輸入法,能直接用標準安裝,不用自己來。也許等大易版權過幾年釋出後,我就不用自己想辦法裝大易。但在那之前怎麼辦?

順道一提,這陣子我開始用手機上 Google 的中文語音輸入,準確度很高,但輸入標點符號很麻煩,而且跨平台很不方便,隱私上也有些顧慮。

行列輸入法

前陣子發現行列輸入法和自由軟體的精神相符
開放理念: 
中文輸入法必須跟發明人的生命及推廣該輸入法的公司分離,當使用者學會之後,不管發明人是否在世,各系統都要能夠繼續支援,使用者才有永遠的保障,就像倉頡和注音輸入法一樣。 
要讓使用者可以永遠使用,只有像倉頡一樣開放授權才可能,因此行列採開放授權,任何一種系統,都可以找工程師把行列寫進系統,成為系統的一部份。 
在生活與工作上,我已儘量使用自由開源軟體,所以行列輸入法發明人廖明德這段話和我很對味。官方網站公布大方公布的內容,就足夠讓我學輸入法。這點令人激賞。

行列的設計和大易一樣好學,一個晚上就能看著字根表打所有字。我相信沒多久就可以把字根表丟掉。目前初步的印象是,行列字根的分類,雖然也很有道理,但感覺上大易保留書寫直覺還是多一點。不過這個問題,應該在熟練之後就會自動消失。

結(未)論

老實說,我才剛學行列,還不知道(這篇仍是用大易打的)。也許我最後會放棄大易,完全轉用行列,也許我會發現行列的問題,再回到大易。但行列原發明人的胸襟,讓我很願意下功夫試試。

另外,我這篇也提到使用智慧型輸入法的潛在問題。也許從沒學過字根輸入的人可以試試能完全掌握打字結果的方法。

Wednesday, August 5, 2015

Sibelius 8 Installation on Non-standard Windows System Drive

UPDATE: This doesn't work for Sibelius 8.0.1. See this post instead for that.

Over the years I have many generations of audio software and plugins installed on Windows, which itself has gone through many version upgrades. I can't remember why but one upgrade called for changing the system drive from C: to K: (probably for a backup reason), and ever since then K: has been my system drive.

Between projects, I decided to give Sibelius 8 a try. However, the installation file (Install_Sibelius.exe, unpacked from Sibelius_8.0.0_Win.zip) downloaded from Avid gave me this error:


Error 1327 invalid drive C:\.


By inspecting the log, I concluded that was hard-coded in the installer (FAIL! To tell the truth, it has been a familiar feeling ever since Avid acquired Sibelius).

I really don't want to change the system drive again, since it would involve the painful process of re-configuring a million things. It's also after their support hours so I did some research, and after some trial and error, this is what worked for me:

1. run cmd.exe as Administrator.
2. Change into the directory where Install_Sibelius.exe resides
3. Run the following command


J:\Users\composer\Desktop>J:\Install_Sibelius.exe /s /v"/qn /l*v %temp%\AvidSibeliusx64.log"



4. Follow the standard procedure to activate the software

That's it.

PS: I very much look forward to Daniel Spreadbury's new score writer.

Wednesday, May 6, 2015

X11 Multi-seat running KDE and GNOME

I was archiving data on my old machine and decided to share my old multi-seat configurations (I don't need multi-seat anymore), in case somebody out there is trying to do the same thing.

It was a 7-year-old Dell PowerEdge server SC-1430 running dual Xeon (8 virtual cores), excellent for compiling, number crunching (machine learning), and video processing (Cinelerra), and on top of all that, it served as a file/media server running RAID 5 over RAID 0.

It was a power beast, in another sense, too, though -- it consumed a lot of power.

Since it was consuming power anyway, I decided to get rid of other computers and maximize its use, by setting up a multi-seat X11, so two users could use it at the same time. There were two sets of everything: two screens (on two NVIDIA cards), two keyboards, two mouses, and two USB sound cards. It worked just like two independent machines. In fact, one seat ran KDE and the other one ran GNOME. The login screen ran KDM, with two login boxes (default to the regular user login name) on respective screens and matching wallpapers. We were even able to play "networked" game against each other.

(Actually I had three sets of xorg.conf to support multi-seat, left-side dual screen, and right-side dual screen, and I used symlinks to dynamically switch to a different configuration. However, there's more info on dual screen setups out there so I skipped those here.)

For me, there were a few files to configure. These are the ones relevant to most people:
  • /etc/X11/xorg.conf
  • /etc/kde/kdm/kdmrc
  • /etc/kde/kdm/backgroundrc.seat0
  • /etc/kde/kdm/backgroundrc.seat1
  • /etc/udev/rules.d/60-dell-keyboards.rules (omit here; see my other post on udev for that)
  • /etc/udev/rules.d/90-creative-xmod.rules
For the sound cards, I just used the GUI setup in KDM and Gnome, respectively, to choose the right pulse audio sound device. I did use the udev to make the names easier to tell them apart.

I ran Arch Linux 64 on that one so the paths may be different if you use a different distro. I apologize in advance for not explaining the details here, many of which were specific to my system back then. I also wish I had time to dig out the document sources for these configs.


/etc/X11/xorg.conf


/usr/share/config/kdm/kdmrc


/usr/share/config/kdm/backgroundrc.seat0


/usr/share/config/kdm/backgroundrc.seat1


/etc/udev/rules.d/90-creative-xmod.rules

Friday, March 6, 2015

憶老方

(My high school homeroom teacher passed away, and this is my tribute and eulogy to him. There's no English translation.)

憶老方

老方是我師大附中三年的導師。年初他病逝,我們694班同學在臉書上私人社團裡,紛紛表達對他的懷念。我人在遠方,無法親自參加公祭,託同學把我對他的懷念和感謝帶上。

在那個時代,給老師取綽號算是不敬。老方知道我們在背後這麼叫他,卻一笑置之。回想起來,「老方」的暱稱,和益師益友的他其實很相襯。

老方教數學,扎實的數學底子,讓我一生受益無窮。但我特別欣賞的,是他在課堂上不做作的態度。有時候他導公式寫了滿黑板,最後發現結果不對,他會請同學幫忙一起看,然後發現之前錯了一步時,他會拍頭一笑,回過重來。這種和學生一起探索的態度,和我與國外博士班指導教授討論想法,竟有異曲同工之妙。後來在工作上,我也用一樣的態度來帶新進的人員。我帶出來的人,特別有實驗精神,敢於表達意見,也讓我的團隊贏得最有創意的名聲。

老方對同學們一視同仁,但我個人有個印象深刻的小故事。

社團是附中特色之一。學生們在社團裡學習經營,發揮創意,結交朋友。但不少社團幹部會因此而影響學業,所以如果成績太離譜,學校會發一張「紅單子」,讓學業成績太離譜的學生不得再擔任幹部。有趣的是,在社聯會(所有社團幹部的聯誼會)裡,「拿紅單子」有時候反而被視為努力經營社團的光榮象徵。

高二時我擔任社團社長,把大部分心力都用在社團經營上,成績一度跌落谷底。有一天,老方把我叫到他辦公室;我當然知道他要說什麼,但我覺得反正他不可能了解社團人的執著,準備好硬著頭皮聽訓,聽完就算了。

進到他辦公室,他看著我笑了笑,問我知不知道他為什麼叫我來。我點了點頭。沒想到他說,「那就好。沒其他事了。」

霎時間,所有我事前的心戰策略全無用武之地。他輕輕一點,讓簡單的真理乍現:你成績怎樣是你的事,你知道自己在幹什麼就好。

雖然這好像是廢話,但我之前在一個逼讀文化(不管是當面逼,還是用制度逼)下成長學習,這是第一次看到師長直接移步側站,讓我自己去面對問題、抉擇及後果。

老方那句話,是我這輩子最後一次讓別人來擔心我的學業。

傳道,授業,解惑,老方也。

Saturday, February 21, 2015

Sage Math Live CD for VirtualBox

Sage Math consists of many mathematical and scientific tools and therefore the library dependencies can be quite hairy. Live CD makes it easier to do some quick and dirty job. However, booting into a live CD is quite inconvenient as far as data transportation goes, so I was trying to use VirtualBox to run a server and connect to it from the host computer.

There's a slight problem though. The Live CD image listed on the official download page is actually a raw image to write into a USB thumb drive. VirtualBox does not support mounting a image as a USB drive. Therefore, we need to convert the bootable USB thumb drive image to another format. I converted it to a hard drive image for more flexibility.

Here's how (I found it in this guide):

$ VBoxManage convertfromraw -format VDI 2014-11-16-sage_6.4-debian_wheezy-live_3.0.5-1.img 2014-11-16-sage_6.4-debian_wheezy-live_3.0.5-1.vdi

By the way, 2014-11-16-sage_6.4-debian_wheezy-live_3.0.5-1.img is a 64-bit Debian image, which needs to be configured properly in VirtualBox.

Thursday, November 27, 2014

Use 802.11n on Asus RT-N16 with OpenWrt

(If you come from OpenWrt's official wiki, skip forward to the section "802.11n" for your answer.)

Overview

It took me a while to figure out how to setup 802.11n in OpenWrt on Asus RT-N16 so I figured I'd share the process, hopefully to save somebody's time.

Background

I've used dd-wrt for a long time (on 4 wireless routers over the years). However, my network setup is getting more and more complex. While dd-wrt allows some customization, the inconsistency between GUI and the command-line configuration made it very hard for me to maintain. For example, editing the DHCP static address table from the GUI is a tedious process because it doesn't sort so it's very hard to detect duplication. I could edit the configuration file directly but the GUI does not reflect my changes correctly. Saving from the GUI can easily overwrite my manually edited config files.

Choosing Alternatives

Therefore, I started to look for an alternative. Besides dd-wrt, Tomato and it's family, and OpenWrt are the other two high-profile router firmware development efforts. And both lineages provide very customizable environment.

However, there are two things I'm looking for.

1. I am looking for a project that's still actively maintained, especially after Heart Bleed, Shell Shock, and Poodle. (Note that these vulnerabilities don't necessarily compromise home routers, but in my environment, I'd rather not take the chance.) While a repository system allows individual package upgrade, I want the base developers to still be around.

2. I'm looking for a project that's owned by a team rather than individuals. In the WRT history, there have been many brilliant individuals that made crucial advances for everyone. However, it has happened a few times when these individuals moved on, their projects died, too.

Therefore, I ended up choosing OpenWrt.

Installation

It was quite straightforward to switch to OpenWrt from dd-wrt, as instructed in the official guide.

Securing the admin access was obvious. However, it took me a while to realize that I also needed to reboot my Cable Modem for it to reset its DHCP. If you are also doing this, I suggest you open all installation guides in the browser first before you flash your new firmware. I had to use my phone to check the guides before my internet was up.

802.11n

This took me a while because the guide is not very obvious. Anyway, after some trials and errors, broadcom-wl was the only one that worked for me (thanks to Stratos about the dependency nas. I already had that so I didn't realize that dependency).


  1. # opkg update
  2. # opkg install kmod-brcm-wl wl wlc
  3. # rm /etc/config/wireless
  4. # opkg install nas
  5. # reboot
Then login to shell again to edit /etc/config/wireless . This is mine.

config wifi-device  wl0
        option type     broadcom
        option channel  1
        option txantenna 3
        option rxantenna 3
        option txpower '20'
        option plcphdr 'auto'
        option frameburst 1
        option disabled 0
config wifi-iface
        option device   wl0
        option network  lan
        option mode     ap
        option ssid     YOUR_SSID
        option key      YOUR_KEY
        option wmm      1
        option encryption 'psk2'
        option disabled '0'
I added plcphdr and frameburst after reading this discussion thread.

Another strange thing to work around is that after reboot, while a client can connect to the router with 802.11n, the DHCP failed to issue IPs. I had to turn the wifi off and on for it to work properly.

# wifi down
# wifi up
I did not spend time debugging. Instead, as a temporary workaround, I added that to /etc/rc.local, which now looks like this:

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
# workaround for Broadcom proprietary driver problem
/sbin/wifi down
/bin/sleep 1
/sbin/wifi up
exit 0

Update: badineu in the comment mentioned that he also needed to manually select the wifi frequency. You may also have to do so if, for some reason, it's not already properly set.

Sunday, October 12, 2014

Arduino IDE 1.5.8 on Banana Pi

I use Arch Linux on Banana Pi. In my previous post, I used a workaround to compile Arduino code on an x86_64 platform and then copy the *.hex file to upload to Arduino from Banana Pi. While i7-4770 is very fast, it's also very power hungry. I dug a little bit and managed to get Arduino IDE 1.5.8 running on my Banana Pi.

If you want to install Arduino 1.0.5-1, Arch Assualt Repo has an almost working version. To make it work, you'll need to install java-rxtx, and replace /usr/share/arduino/lib/librxtxSerial.so with a symlink to /usr/lib/librxtxSerial.so , and also RXTXcomm.jar -> /usr/share/java/rxtx/RXTXcomm.jar

Now, this is how I got version 1.5.8 working (thanks to this post for a pointer):

Use the following PKGBULID (modified from its AUR for x86 and x86_64) to build and install a package:

# Maintainer: Lauri Hakko # Contributor: PyroPeter # Contributor: darkapex pkgname=arduino-beta epoch=1 pkgver=1.5.8 pkgrel=1 pkgdesc="Arduino SDK Beta release" arch=('armv7h') url="http://arduino.cc/en/Main/Software" options=(!strip) license=('GPL') depends=('avr-libc' 'libusb-compat' 'java-runtime') install="arduino.install" conflicts=('arduino' 'arduino-toolchain') provides=('arduino') source=("http://downloads.arduino.cc/arduino-${pkgver//_/-}-linux32.tgz" 'arduino' 'arduino.png' 'arduino.desktop') md5sums=('289b1e3ad64f29db3ed13b06880dce40' '5e385c8cba80ca1b4227b162e4cad5cd' '9e36d33891d5e68d38ec55d1494499a5' 'eebc4d6495864bea99ad057af801afb9') package() { cd "$srcdir/arduino-${pkgver//_/-}" # arduino excutable should accept arguments sed -i 's/^java .* processing.app.Base$/\0 "$*"/' arduino mkdir -p "$pkgdir"/usr/{bin,share/{doc,applications,pixmaps}} # copy the whole SDK to /usr/share/arduino/ cp -r . "$pkgdir/usr/share/arduino" # at least support the FHS a little bit: install -m755 "$srcdir/arduino" "$pkgdir/usr/bin/arduino" ln -s /usr/share/arduino/reference "$pkgdir/usr/share/doc/arduino" # desktop icon install -m644 "$srcdir/arduino.desktop" "$pkgdir/usr/share/applications/" install -m644 "$srcdir/arduino.png" "$pkgdir/usr/share/pixmaps/" }

This version won't run because /usr/share/arduino/hardware/tools/* are compiled for x86. We need those files compiled for Arm7. Let's remove /usr/share/arduino/hardware/tools now.

Download a pre-compiled version 1.5.4 by UDOO folks (big thanks for their efforts!). Go to their download page, click on Driver & Tools, and click on Arduino IDE for UDOO. Unpack the archive. We only need arduino/hardware/tools . Move it to /usr/share/arduino/hardware/tools

Since 1.5.8 above expects avr tools in /usr/share/arduino/hardware/tools/avr, and Arch installs it separately, so we need to make another two symlinks.

$ ln -s /usr/bin /usr/share/arduino/hardware/tools/avr/
$ ln -s /etc /usr/share/arduino/hardware/tools/avr/

There's one more file we need to replace: arduino/lib/libastylej.so . I just installed astyle from archlinuxarm.org and do a symlink libastylej.so -> /usr/lib/libastyle.so

That's it.

Friday, October 10, 2014

Control Arduino IDE 1.5.8 with command line

My workbench for Arduino development does not have enough space for a high power PC so I use lower power Arm devices (Raspberry Pi, Banana Pi, and Yun Shield) instead. However, Arduino IDE 1.5.x is not well supported yet (Raspbery Pi has a working version but not the other two, which I prefer. UPDATE: I figured it out.), and several Makefile solutions are still buggy against 1.5.x's libraries.

My temporary solution is to outsource the compiling to the more powerful machine (my i7-4770 running Arch 64 finishes compilation almost instantly, as opposed to 40 seconds on Raspberry Pi), and grab the compiled *.hex file back to these Arm devices to upload to Arduino via the USB serial connection.

As of October 4, 2014, Arduino IDE 1.5.8 has a buggy command line parameter passing, so I cannot compile the code remotely without doing a remote X session, and I want to avoid having to run an X server on these Arm devices (although Banana Pi actually runs X quite well). Therefore, I use the following hack to trigger the compiling via the command line.

$ DISPLAY=:0 xdotool search --name "Arduino 1.5.8" windowactivate --sync windowfocus mousemove --window %1 10 30 click 1

xdotool searches for a window whose title contains "Arduino 1.5.8", activates the virtual desktop it's on, focuses on the window, moves the mouse cursor to coordinates (10,30) relative to the application window (where the "Verify/Compile" button is) and then clickes on it to trigger the compilation.

For some reason sending ctrl+r doesn't work for me. If anyone knows why, I'd love to know.

$ # this doesn't work
$ DISPLAY=:0 xdotool search --name "Arduino 1.5.8" windowactivate --sync windowfocus key ctrl+r

Wednesday, September 11, 2013

Some trivia for search engines

For those who have the need to search for these answers. :)

The first ruler of England was "Egbert", King of Wessex.  (See World History, Historical Figures).

The "Mayflower" Compact was America's first written constitution.  (See U.S. History).

Francis Lightfoot Lee, one of the original signers of the Declaration of Independence, was a "farmer" by trade.  (See U.S. History, Signers of the Declaration).

James Monroe, 5th President of The United States, was the son of "Spence" Monroe and Eliza Jones.  (See Presidents' Biographies).

"glansnost" is another word for openness or candor.  (See Language, Foreign Words).

A "bug" is a mistake that occurs in a program within a computer.  (See Language, Computerese).

Sandy Koufax won the Cy Young Award "3" times.  (See Sports, Baseball).

"Mach" is a word used to describe supersonic speed.  (See Weights, Measures and Numbers, Breaking the Sound Barrier).

According to the National Film Registry, the film Casablanca was released in the year "1942".  (See Arts and Media - Movies, National Film Registry).

Cary Grant's original first name was "Archibald".  (See Noted Personalities, Original Names).

What famous boxer hails from the Bluegrass State?  "Muhammad Ali".  (See States of the Union, Kentucky).

Peggy Fleming won the Olympic gold medal in women's singles figure skating in "1968".  (See Sports, Winter Olympics).

More wheat and rice is grown in "China" than any other country in the world.  (See Agriculture).

William "Tyler" Page, Clerk of the U.S. House of Representatives, wrote "The American's Creed."  (See Great Seal, American's Creed).

Clint Eastwood was born in "San Francisco", California.  (See Noted Personalities, Entertainers).

In the year 1540, Spanish explorer Hernando Alarcon discovered the "Colorado" River.   (See World Exploration and Geography, Early Explorers of the Western Hemisphere).

"Batman" was the top grossing movie of 1989.  (See Arts and Media - Plays; Movies, All Time Top 50 American Movies, 1989).

Elzie C. Segar was the creator of the cartoon "Popeye".   (See Noted Personalities, Cartoonists)

Friday, November 30, 2012

Thinn Ooh Ooh (Darkening Sky) for Viola Ensemble 天黑黑 (中提琴合奏)

I was commissioned by Tim Deighton early this year to write this piece for his viola ensemble.

這是我今年初受中提琴家 Tim Deighton 委托的作品。


Monday, November 19, 2012

Segmentation of Bopomofo Symbols

A friend of mine is working on a project in which he needs to display Bopomofo (Chinese phonetic symbols used in Taiwan). He decided to display, in his program, each syllable as one unit that consists of vertically stacked phonetic symbol. To generate those well positioned symbols, he used MS Word to type all syllables he needs, captured the screenshot as images, and asked me to segment them. He gave me 26 files in total. Each files has several lines of something like this:

Monday, December 26, 2011

Homeless

This post is a translation of my other post in Chinese.  I wrote that to share my personal reaction toward a recent incident in Taiwan: the municipal administration used water jets to drive away homeless people in the park in a cold evening.

Please note that since this is a direct translation from the original Chinese post, the composition flow may not be as natural to English readers. Please bear with me and hear out what I have to say, if you are interested in reading this anyway.



When I moved from Southern California to Philadelphia for my graduate study in 1998, I was shocked to see so many homeless people. I witnessed a country in which the rich can personally own a hill, while the poor would seek food in the garbage can.  While some spend their afternoons watching seagulls with their beer on the beach, some others try to survive a cold night by staying close to the external vent of a building's heater.

街友

(English readers, you may be interested in my English translation of this post.)

記得1998年從美國西岸加州到美國東岸費城讀書時,第一次見到眾多的遊民,大為震憾。美國這個國家,有人富有到坐擁山頭,有人窮到得從垃圾筒翻出別人吃剩的便當出來填肚子;有人每天下午到海灘看沙鷗喝啤酒,有人每天晚上得縮在高樓旁的暖氣通風口取暖度冬夜。

那時候我很幸運,獎學金夠我過日子,也夠幫一兩位社區內的街友多買個便當。日子久了,和他們聊起來,才知道他們幫國家打仗受傷,戰後政府沒有好好照顧他們,他們寶貴的年輕時間都在戰場上耗掉了,退伍後年紀大要再回學校已是很困難。付擔不起房租,所以居無定所;想要好好老實找份工作,大部份的業主看到他們沒有個固定的住址,都不願意給他們機會。收容所的環境很不好,通風不良,傳染病問題嚴重,生了病很難好,再加上收容所的工作人員對待這些遊民的人態度極度不佳,讓他們寧可餐風露宿,也不願自尊被人踐踏。