2014/05/10

Let's type cangjie on Ubuntu Hong Kong People

Tonight I am so happy that I can find (and install it successfully) a nice Cangjie software on Ubuntu which I am going to document down how to make it works.


By the way, this library originates from our Hong Kong People. Proud of you ahahahahah

Let's start.

To be honest, I believe they havn't written a good documentation for end user. Well.... common problem in open-source projects. Never mind. That's why I wrote this blog post.

Here is their PPA. There are 2 ways for installation.

Install by adding the ppa via add-apt-repository
  • sudo add-apt-repository ppa:haggenso/ibus-cangjie-ppa
  • sudo apt-get update
  • sudo apt-get install ibus-cangjie
If you fail (like me), here is another way.
  • sudo vi /etc/apt/sources.list
  • Paste following contents
deb http://ppa.launchpad.net/haggenso/ibus-cangjie-ppa/ubuntu precise main 
deb-src http://ppa.launchpad.net/haggenso/ibus-cangjie-ppa/ubuntu precise main 

  • sudo apt-get update
  • sudo apt-get install ibus-cangjie
  • Restart the keyboard icon (or logout, reboot etc) on your top-right hand corner
  • You can see a gear icon here if you get nothing wrong



















FAQ

  1. No keyboard icon?
Read this. It guides you how to setup an ibus on your ubuntu


Enjoy :D 
終於打到中文啦 哇哈哈哈哈哈

2014/04/16

Pattern explore - Decorator

Abstract

Currently, I am revising pattern design on Software Develop. In order to have a deep understanding and goooooood memorable experiences on the patterns I revised, I am going to drop down the notes or codes in this blog. So, let's start on decorator

Decorator

Intent:
1. How to implement the objects that give the new functionality.
2. How to organize the objects for each special case.

To summarize, it is a very good pattern for chaining up a sequences of commands!

Use case


Imagine that you have follow commands on your hand:

ping(), iperf(), ssh(), get_bw(), telnet()

Then, your task is doing a bandwidth measurement between 2 network devices. So you will came following command sequences.

Get_BW_BY_SSH() if (ping()) // check if those 2 devices are alive host = ssh() // connect to host ret = host.iperf() // run iperf() get_bw(ret) //process results....
It sounds perfect. However, what if I need to support the connection protocol from ssh to telnet? Then, you need to add a switch on connection part.

Get_BW(protocol) if (ping()) // check if those 2 devices are alive host = switch(protocol){ "ssh": ssh() "telnet": telnet() } ret = host.iperf() // run iperf() get_bw(ret) //process results....
Not bad. OK! what if I need you to color the results if BW higher than certain thersold ?

Get_BW_BY_SSH_WITH_COLOR(protocol, thresold) if (ping()) // check if those 2 devices are alive host = switch(protocol){ "ssh": ssh() "telnet": telnet() } ret = host.iperf() // run iperf() bw = get_bw(ret) //process results.... if (bw > thresold) color(bw)
Obviously, We need a new function with each new requirements. Moreover, client sides will need to know which one they should call in order to fulfill what they need. I hopes I can convince you that this is a bad design.

You may argue that you can keep them in one function so that we don't need to add codes on client sides. However, your function must be full of "if-then-else" or "switch" for logic control. It will totally mess up your codes.

Decorator allows you to solve them properly. Consider the following codes:

Class Task { construtor: function (Task t) { this.task = Task; } do: function (val) {//your specific code} } Class Ping extends Task { construtor: function (Task t) { this.task = Task; } do: function (val) { ret = ping(); this.task.do(ret); } } Class Iperf extends Task { construtor: function (Task t) { this.task = Task; } do: function (val) { ret = val.iperf(); this.task.do(ret); } } Class GetBw extends Task { construtor: function (Task t) { this.task = Task; } do: function (val) { ret = get_bw(val); this.task.do(ret); } } Class Color extends Task { construtor: function (Task t) { this.task = Task; } do: function (val) { ret = this.task.do(val); color(ret); } } operation = new Ping(new SSH(new Iperf(new Color(new GetBw())))) operation()
Although this is an incomplete code, it shows how decorator works.


  • Specific Tasks are inherited from Class::Task and implement the same interface (function, method, whatever you like to call) do().
  • Instantiating those specific tasks by passing another tasks to their constructor as a refernce allows chaining the operation.
  • By modifying how to instantiate those instance, you can manage which order you would like to run those tasks. 
  • The client side know nothing about it since they are still calling operation().
  • The ordering of this.task.do() and your specify code is not matter. Just like Class::Color, it calls GetBw() before running its business logic.


See? That's the power of Decorator.

Updated on: 20/4/2014

2014/04/08

Ubuntu 12.10 missing a desktop

Abstract

Today is a bad day. I found the damn ubuntu desktop gave me a blank wallpaper only while I would like to start working. Even by the help of google, it took me times for dealing with it. Damn! 

Anyway, I am going to listing down the methods I tried.

Methods

1. Re-install the graphic card driver

Actually, this is not work for me this time

2. Re-install ubuntu desktop

It works for me. However, I suggest you simply issue the following commands
sudo stop lightdm
sudo apt-get remove --purge ubuntu-desktop

sudo apt-get install ubuntu-desktop
sudo start lightdm
Note: Remember to reboot your computer for checking the solution work or not


2014/03/23

Install / Upgrade nodejs on ubuntu 12.10 / 13.04 /14.04

Abstract

According to my boss, I am going to develop a testing tool with UI and bandwidth testing within one week......
So, order is order and boss is boss. Since I need to complete this task anyway, I am going to develop on a cutting edge web application server nodejs :D

Let's go

I have checked out the official node js version on ubuntu 12.10 is 0.6.x. After googling a while, I found this link is very useful.

Recommend reference

what is node.js

Update on 2014/03/23

- This solution works on ubuntu 13.04

Update on 2016/01/26

- This solution works for Ubuntu 14.04

2013/12/12

Install php5-rrd module on ubuntu 12.04

Abstract

Since I am running php-5.4 on ubuntu 12.04, apt-get install php5-rrd is not work due to the problems of dependency. I need to do it via pecl alternatively.

Steps

1. Make sure your pecl is installed properly.
2. apt-get install php5-dev
3. pecl update-channels
4. pecl install rrd
5. cd /etc/php5/mods-available
6. cp {?.ini} rrd.ini 
//note that simply copy a file among this directory and modify the extension value to rrd.so
7. cd ../conf.d
8. ln -s ../mods-available/rrd.ini 20-rrd.ini

done

Check

php -v
php -m | grep rrd


2013/11/20

"%.*s" in printf()

Background

Currently, I am dealing with regex example in C.  There is a abnormal printf command.
......
printf ("'%.*s' (bytes %d:%d)\n", (finish - start),  to_match + start, start, finish);
......
Ouput:
$& is '1 is nice 2' (bytes 5:16)
I am wondering why there are 3 "%s" format options but there are 4 parameters to map those options.

Dig deeper...

To make the story short, "%.*s" is where the amazing happen. This option take 2 arguments: length of the string and the starting point of a string. (XXX: so ?) OK. Take a look the example code below.

#include <stdio.h>

int main(int argc, const char *argv[])
{
        char a[] = "0123456789";

        int len, offset;
        len = 4;

        for (offset = 0; offset < 3; offset++) {
                printf("%.*s\n", len, a + offset);
        }

        return 0;
}

Output:
0123
1234
2345

In other word, "%.*s" allows you to print a subset of a string without doing tedious jobs like following.

char *b = (char *) malloc(4+1);
memcpy(b, a+offset, len);
b[len+1] = '\0';
printf("%s\n",b);



2013/11/17

Introduction to enyoJS

Background

Diverged from xtuple paragraph, enyo is one of xtuple dependencies. Or, in other words, xtuple use this framework to build their client side UI.

Introduction

enyo js
http://enyojs.com/about/
http://enyojs.com/get-enyo/#Bootplate
Difference between enyo and jQuery
jQuery focus on manupliating HTML elements while enyo focus on encapsulating HTMLs as a module and reuse them

Dig deeper

1. Cloning their "blootplate" and play around

The 1st question I would like to ask is what blootplate is.
After reading a while from their reference, I understand several things.
a) You can produce a web page with a minify source easily if you can make use of their shell script and directory structure.
b) If you have not interested on building an APP they claimed like me(well... it means a HTML5 webpage), you can simply read source/App.js. This file control what "debug.html" look like.

2. Diving back to their developer guide

Well... their developer guide make more sense than then point 1 I just pass-through.
I understand 2 more keywords in enyo namespace:
kind: A kind is a JavaScript constructor for an object that's been defined using the enyo.kind method. (That's why you can write `new App()`)
enyo.Control: A kind provided by enyo's core. A factory for users like us to create enyo.instance with user-defined properties.
enyo.Control() VS enyo.kind:
var t = enyo.Control(.....);
t.renderInto(document.body);
enyo.kind({name:'test',kind:enyo.Control...});
var k = new test();
k.renderInto(document.body);


In other word, enyo.kind allows you to publish your enyo.instance to a global namespace as a constructor while enyo.Control return a pointer of your enyo.instance.

3. Walk through their example

Here is their tutorial and here is my github repository, which folk from enyo.bootplate, to play with the provided example.
Notes:
1. "published":
properties insides "published" will be given a setter and getter method.
2. "event handler":
There are 2 parameters, object that's the source of the event and the event object, will be passed into the event handler.
3. "jsonp example":
Since Twitter have updated their APIs, the original example does not work. I have coded another apps in order to try their Ajax wrapping. Not Bad :D

4. Summery

It is fun for me to code with enjo JS. However, there are no too much online sources for you. If you get problems with enjo JS, you better be able to solve it yourself........
PS: Currently, # of jquery tag on stackoverflow is 389,821 while enyo is 120....

5. Useful links

2013/11/16

Introduction to OAuthn

Background

While I am dealing with Guildwars2 (umm it is nice game :D) web API, I found that they are going to evolve their API with OAuth. So, I am really wondering what is OAuth and what it can do. 

So... what is OAuth?

According to their page definition, it is a new protocol aims on providing an efficient way to control the web-application access rights. In other word, web-applications can ONLY access what you have granted them.

Conceptually, they have defined 3 entities. Users (You and me), Consumer (web-applications) and Service Provider (eg Twitter).
Overview of Oauth

The diagram in left hand side is what I got after digesting the data in OAuth webpage. The ultimate goal of consumers is getting protected resources which manged by Service Provider.

Before, web-application may get users credential in order to archive the above goal.

This is not a good approach since web-applications can do whatever they want after getting your credentials.

Therefore, that's why OAuth introduced. By the help of the token concepts, all accesses must be granted by Service Providers and Users without letting Consumers know Users credentials.

Flow chart from OAuthn to show how it works




2013/11/12

Install phpunit on ubuntu 12.04

Background
OS: ubuntu 12.04

Steps
sudo apt-get install phpunit
sudo pear upgrade pear
sudo pear channel-discover pear.symfony.com
sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover components.ez.no
sudo pear channel-discover pear.symfony.com
sudo pear install --alldeps phpunit/PHPUnit

Testing
phpunit --version
PHPUnit 3.5.5 by Sebastian Bergmann.

Reference
http://www.giocc.com/installing-phpunit-on-ubuntu-11-04-natty-narwhal.html

2013/11/10

Library for drawing Graph on web: jsPlumb.js

Background
jsPlumb is a open-source javascript library for drawing graph on web platform. FYI, please go in their official website http://jsplumbtoolkit.com/home/jquery.html. There are many demos and relevant documentations for you to start your development.

My opinions
To be honest, I have not read all of the documentations. However, in beginner point of view, their documentation is not programmer friendly and examples are quite hard to follow.

After working for few hours, I have written a test website to play around with this library. Here is the link: https://github.com/mondwan/jsplumb_test

Two things I would like to drop down after building up the above test page
1. No idea for why css position:relative is required for jsPlumb.draggable() function properly. Actually, I have reported it as a bug to jsplumb on github. However, they claim that this is not a bug.

2. jsPlumb.draggable() is not a pure wrapper which means jsplumb element cannot be updated correctly if you are using 3rd party dragging library. (I have struggle a while...)

Install nvidia driver on Ubuntu

Background
OS: ubuntu 12.10
Graphic card: GTX 560

Goal
Install the driver from nvidia official website.

Steps
0. Install required package
`sudo apt-get update`
`sudo apt-get dist-upgrade`
sudo apt-get install build-essential linux-source linux-headers-`uname -r`
1. Make sure your graphic card module and OS system
`lspci -v | less`
`uname -a` # 32bit or 64bit
2. http://www.geforce.com.tw/drivers get your device installation file
3. Reboot your machine and enter recovery mode
4. Enable network mode (In order to get the write access on grub)
5. Enter root shell on grub and modify file
/etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="nomodeset"
6. Go to the directory where you download the *.run file
`chmod 755 *.run`
`./*.run`
7. Follow the installation shell.
PS. Press yes and yes and yes....
8. Reboot after installation finished
9. Enjoy :D

CAUTION
You may fail to boot ubuntu again if you have already installed nvidia-* provided by apt-get.
`sudo apt-get remove --purge nvidia-*`
In other word, make use you pick either one way for installing nvidia driver instead of both.

2013/11/04

SCMBUG: branch name validation

BACKGROUND
Assuming that your svn and bugzillia have linked up via scmbug already.

GOAL
Modify the validation rules for branch name on scmbug.

STEPS
1. Modify <Your_SVN_Dir>/hooks/etc/scmbug/glue.conf
2. Read lines under Policy block
3. Done