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


2013/10/31

Apache2 directory access right on ubuntu 12.04

Objective
1. Forbid others to browse folder in my web server

I don't know why the default configuration of the apache2 allows others to browse your directory contents. For security reasons, I am going to turn this feature off. As a result, others will get a 403 if they are trying to access my web directory.

Step
1. Modify /etc/apache2/sites-available/default
Delete the indexes in the Options under directory /var/www/

2. Restart your apache2

3. Done


Reference
https://help.ubuntu.com/12.04/serverguide/httpd.html#http-configuration

2013/10/30

Setup a git server via http protocol

Background
1. apached2 installed
2. Ubuntu 12.04 LTS
3. git installed
4. You are root

Steps
Enable git on http (git push should be work after that)
Follow the 2nd reference link, to summarize
1. Import dav module (I have no idea what dav is at this point)
2. Modify directory configuration so that others can access your git directory on your web server
3. Actually I use following config on git.conf since I don't need authentication
    <Location /my-new-repo.git>
       DAV on
    </Location>
4. Restart your apache

Create git repository on your web server (git clone should be work after that)
Follow the 1st reference link.
(EDIT
/* create from existing project */
$ cd /var/www/htdocs/ $ git clone --bare /path/to/git_project gitproject.git
$ chown -R www-data:www-data ./gitproject.git $ cd gitproject.git $ mv hooks/post-update.sample hooks/post-update $ chmod a+x hooks/post-update
$ git update-server-info
/* create from scratch */
$ cd /var/www/htdocs/ $ git init --bare gitproject.git
$ chown -R www-data:www-data ./gitproject.git $ cd gitproject.git $ mv hooks/post-update.sample hooks/post-update $ chmod a+x hooks/post-update
$ git update-server-info
)

Testing
git clone http://<hostname>/<dir>.git
$(some work)
git push

Linking up ticket system Bugzilla with git
https://github.com/gera/gitzilla seems to be a solution. However I cannot make them work. Leave me a message if you know how :'(

Enjoy :D

Reference
1. http://git-scm.com/book/en/Git-on-the-Server-The-Protocols
2. http://www.kernel.org/pub/software/scm/git/docs/howto/setup-git-server-over-http.txt

2013/10/28

Upgrade php from 5.3 to 5.4 in Ubuntu 12.04 LTS

By default, The version of PHP in Ubuntu 12.04 LTS is 5.3. Somehow, I need the features in 5.4 so that's why I wrote it down for future reference.

Commands
`sudo add-apt-repository ppa:ondrej/php5-oldstable`
`sudo apt-get update`
`sudo apt-get install php5`

If there is warning about missing a SSH module, 
clear the contents in /etc/php5/cgi/conf.d/ssh2.ini in order to eliminate the warning

2013/10/25

Mount FTP/NFS in ubuntu

Abstract

Mounting a FTP or NFS into a local directory.

Background

Ubuntu 12.04 LTS

Let's start

NFS
`sudo apt-get install nfs-common`
`showmount -e NFS_IP`
PS. this will show a mountable directory on your NFS
`mount -o soft NFS_IP:<dir in last command> <local_directory>`

FTP

`sudo apt-get install curlftpfs`
`curlftpfs user:pass@ftp.yourdomain.com ~/ftpfolder/`

If you want to un-mount the directory,
`sudo umount  <dir>`

Permanent mounting

add following line into /etc/fstab
curlftpfs#ftpUsername:ftpPassword@ftp://ftpUrl /localDirectory fuserw,uid=1000,umask=0777,user,suid,allow_other,exec,auto,utf8 0 1


Reference


2013/10/21

Learning u-boot Part 2

My goal
I need to some how implement a feature for loading firmwares via ethernet cable only (IE fading out no SERIAL CONSOLE RS232). A suggestion from my supervisor is starting from bootloader. Basically, that's why this thread coming out :D

1. Direction
According to the /doc/README.Netconsole, u-boot provides an access via netcat. So, this is my starting point.

2. Enable netconsole
Netconsole is disabled by default of my board setting due to minimize the files size of that executable file (I guess). So, the following recording how I enable netconsole.

According to
/common/device.c:240~242
240 #ifdef CONFIG_NETCONSOLE
241         drv_nc_init ();
242 #endif

It is clear that we need to define that constant in order to enable netconsole.

Add lines
#define CONFIG_NETCONSOLE /* enable nc */
into /includes/configs/<board>.h

Recompile the u-boot binary and loading into the device.
PS. How to load bootloader into the device will not be discussed here.

For now, bootloader should be able to use nc.

3.  Follow up
Keep following the README.Netconsole, execute following commands via serial console.
setenv nc setenv stdin nc\; setenv stdout nc
setenv ncip <YOUR_SERVER>
setenv netmask <YOUR_SERVER_NETMASK>
saveenv
run nc

In your server run the following script file,
#! /bin/bash

[ $# = 1 ] || { echo "Usage: $0 target_ip" >&2 ; exit 1 ; }
TARGET_IP=$1

stty -icanon -echo intr ^T
nc -u -l 6666 < /dev/null &
nc -u ${TARGET_IP} 6666
stty icanon echo intr ^C

# interupt by CTRL+T
# $1 is your device ip

For now, magic happen :D
You can interact with the device as if you are using serial console cable.

4. Summery
I can setup a network link between embedded device and my pc. The rest of the tasks are putting things together. For example, when and how to enable netconsole on the embedded device. I will cover these stuffs later on (I hope) since I have no progress till now.

Learning u-boot Part1

Firstly, I have no idea how many parts I will write on this topic "Learning uboot".

Introduction
Namely part 1, let's take a look what u-boot is. Official website for u-boot is http://www.denx.de/wiki/U-Boot/WebHome.
u-boot is a kind of bootloader on embedded device (eg. routers). Mother Board initialization is what it suppose to do.

What happen after powering on your device
Power on -> bootloader (ROM) -> firmware (STORAGE somewhere) -> user-space interface ( COMMAND LINE or something like that)

My goal
My job is implementing a function for loading firmwares via cat5 cable (IE no SERIAL CONSOLE RS232). A suggestion from my supervisor is starting from bootloader. Basically, that's why this thread coming out :D

1. Browsing the u-boot project
Since I have no expereince on related topics, I can only read documentations, tutorials, googling etc....
Here is my summery for files useful for my goal.

Assume prefix <u-boot project> is presented
/include/configs/cavium_cns3000.h   /* u-boot console default environment variable value */
/board/cavium/cns3000/vega.c           /* board manufacturer info */
/common/env_common.c                   /* where environment variable will be assign */
/common/devices.c                            /*  How devices will be enabled */
/common/main.c                                /* How Interactive  Shell implemented */
/net/net.c                                            /* How tftp, arp, ping implemented */

2a. Execution flow
cpu/..../start.S
board/.../lowlevel_init.S
board/.../lowlevel_init.c
cpu/.../start.S
lib_.../board.c

2b. Command flow
/common/main.c
main_loop() -> readline() -> run_command() ->
/common/command.c
find_cmd() -> corresponding function()

3. Short summery
Compile issue:
Make sure your board model is supported by u-boot. (Ask your board manufacturer what to do for bootloader issue)
U-boot provides you a way to build relevant configuration files. (`make <board>_config`)
Make sure your tool chain directory is presented in $PATH.

Script issue:
Following commands are useful for scripting in u-boot.
setenv; setting environment variable
saveenv: saving environment variable permanently on rom
printenv: printing environment variable
run <var>: run the variable contents
coninfo: list of available devices


Script example:
setenv loader tftpboot 0x800000 loader.bin\;erase 0x10000000 +\$(filesize)\;cp.b 0x800000 0x10000000 \$(filesize)\;reset
run loader


Reference
Illustrate the u-boot project hierarchy in chinese
http://gordenhao.pixnet.net/blog/post/29189867-%5B%E8%B3%87%E6%96%99%5D-u-boot-%E7%B0%A1%E4%BB%8B
How to compile uboot
http://home.educities.edu.tw/fushiyun2000/gameconsole_snk_neogeox_hack_compile_official_uboot_program.htm
Execution flow
https://sites.google.com/site/myembededlife/Home/u-boot/u-boot-startup-sequence

2013/10/18

"va_*()" in c programming

Quick and dirty summery
va_*() are macros helping you to implement functions with dynamic arguments numbers.

Dig deeper
what is va_*()  ?
They are va_start(), va_arg(), va_end() respectively. Those macros will be used if you want to implement a function with vary arguments. For example, printf().

va_start(); /* call before va_arg(), otherwise va_arg() cannot function properly*/
va_arg(); /* return 1st, 2nd, 3rd.... arguments for 1st, 2nd, 3rd ...calls */
va_end(); /* call before returning value */

There are some examples codes on the reference link.

Reference
http://tw.myblog.yahoo.com/jw!kg_rIFWTHgO4kRtDoy15QxVeWQ--/article?mid=21&prev=22&l=f&fid=5

Network interface in Ubuntu

Here are notes about how to configure ubuntu's network setting without GUI.

Make sure you are root.

System: Ubuntu 12.04
Manual page: interfaces (5)

$>vi /etc/network/interfaces


auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
        dns-nameservers 8.8.8.8
        address 192.168.0.22
        netmask 255.255.255.0

        gateway 192.168.0.1

$>/etc/init.d/networking restart

PS
1. auto eth0 is necessary otherwise your eth0 will not be up on system startup
2. dns-nameservers option will override /etc/resolvd.conf. 

Reference link
https://help.ubuntu.com/10.04/serverguide/network-configuration.html

By the way, commands for run-time network interface's configuration
#Static
sudo ifconfig eth0 10.0.0.100 netmask 255.255.255.0
#DHCP
sudo dhclient eth0
#STOP DHCP
ps aux | grep dhcli
kill .....

2013/10/16

"extern" in c programming

Quick and dirty summery
1. extends the visibility for a variable or function
2. While using with variable, it declares a variable but not defining it.
3. Special case for (2) is "extern int bar=0;", it treat as definition


Dig deeper
Declaration := A variable or function signature exists somewhere in the program but the memory is not allocated for them.
Definition := Despite the stuff declaration does, it also allocates memory for that variable/function.

PS.
/* function */
int foo (int arg1, int arg2); /* Declaration */
int foo (int arg1, int arg2){
    /* Definition */
     return 0;
}
/* variable */
extern int bar; /* Declaration */
int bar=0; /* Definition */



Reference:
http://www.geeksforgeeks.org/understanding-extern-keyword-in-c/

"volatile" in c programming

Quick and dirty summery
"volatile" is a keyword to force compile to fetch a variable's value from memory every-time it reads this variable during the variable's life time.

Dig deeper
Since there maybe optimizations on the C compiler (maybe true or not), compiler will cache the value of a variable if there are no obvious side effects on that variable. "volatile" is a keyword to tell compiler not to do optimization on that variable.



Reference:
http://cboard.cprogramming.com/c-programming/73163-volatile-keyword.html

2013/10/15

Hello World

Hello World!!!
That's my first post on my blogger. As the name of this blogger, I will see this blog as a place for me to manage and drop down notes :D