2010/04/26

sqlite3 - explore a .db !

Got a .db and tried to find what's inside... :)

$ sqlite3 realtek.db 
SQLite version 3.6.16
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .databases
seq  name             file                                                      
---  ---------------  ----------------------------------------------------------
0    main             /nfstmp/realtek.db                                        
sqlite> .tables
t_file_uid  t_playlist
sqlite> .schema
CREATE TABLE t_file_uid (file_uid INTEGER not null,file_path VARCHAR(512) not null,PRIMARY KEY(file_uid));
CREATE TABLE t_playlist (channel_id INTEGER not null,flip_id INTEGER not null default 0,disk_partition_id VARCHAR(64) not null,file_uid INTEGER not null,resume_play_time INTEGER not null,timestamp DATA not null,PRIMARY KEY(channel_id, file_uid));
sqlite> select * from t_file_uid;
-2071458204|/tmp/usbmounts/sda1/idownloader/20100108危機倒數/AVSEQ01.MPG
-1756245902|/tmp/usbmounts/sda1/idownloader/Email/demoVideo@noMovie.com/20091224十月圍城DVD/cd1.rmvb
-1727616751|/tmp/usbmounts/sda1/idownloader/Email/demoVideo@noMovie.com/20091224十月圍城DVD/cd2.rmvb
-1593361965|/tmp/usbmounts/sda1/idownloader/Email/demoVideo@noMovie.com/20091214福爾摩斯/Sherlock Holmes.rmvb
-1169771785|/tmp/usbmounts/sda1/idownloader/20100108爆裂警官/cd1.rmvb
-1141142634|/tmp/usbmounts/sda1/idownloader/20100108爆裂警官/cd2.rmvb
-364296195|/tmp/usbmounts/sda1/idownloader/2012.iso
-171856212|/tmp/usbmounts/sda1/idownloader/Email/demoVideo@noMovie.com/20091217阿凡達/[无极电影-www.wujidy.com].阿凡达-cd1.rmvb
-154010674|/tmp/usbmounts/sda1/idownloader/2012/2012.avi
-143227061|/tmp/usbmounts/sda1/idownloader/Email/demoVideo@noMovie.com/20091217阿凡達/[无极电影-www.wujidy.com].阿凡达-cd2.rmvb
303893828|/tmp/usbmounts/sda1/idownloader/IronMan2008.rmvb
1141848971|/tmp/usbmounts/sda1/idownloader/WallE.iso
1315910659|/tmp/usbmounts/sda1/idownloader/Monga/VIDEO_TS/VIDEO_TS.IFO
1734234585|/tmp/usbmounts/sda1/idownloader/20100108危機倒數/AVSEQ0.MPG
sqlite> select * from t_playlist;
99|0|0|-1727616751|0|sda1$947285315$6994$cd2.rmvb
99|0|0|-1756245902|0|sda1$947285315$6994$cd1.rmvb
99|0|0|-143227061|0|sda1$947285315$77d6$[无极电影-www.wujidy.com].阿凡达-cd2.rmvb
99|0|0|-171856212|0|sda1$947285315$77d6$[无极电影-www.wujidy.com].阿凡达-cd1.rmvb
99|0|0|-1593361965|0|sda1$947285315$eff6$Sherlock Holmes.rmvb
99|0|0|303893828|0|sda1$947285315$8d3c$IronMan2008.rmvb
99|0|0|-154010674|0|sda1$947265134$f09b$2012.avi
99|0|0|-1169771785|0|sda1$947264575$a0b8$cd1.rmvb
99|0|0|-1141142634|0|sda1$947264575$a0b8$cd2.rmvb
99|0|0|-2071458204|0|sda1$947264471$9fac$AVSEQ01.MPG
99|0|0|1734234585|0|sda1$947264471$9fac$AVSEQ0.MPG
99|0|0|-364296195|7|sda1$947264471$8d3c$2012.iso
99|0|0|1141848971|0|sda1$947264471$8d3c$WallE.iso
99|0|0|1315910659|0|sda1$946658411$e85d$VIDEO_TS.IFO
sqlite> .exit
$  

2010/04/21

A simple MineSweeper on Realtek 1073/1283 board.

It's just an idea to have a game on my Realtek 1073/1283 board. Preliminary version was developed on Ubuntu 9.10 to generate a random mine map. The GUI on Realtek board helps the completion of the simple game. No score, just for fun !!!

















A simple calculator on Realtek 1073/1283 board

The CalcAP is implemented due to a programming quiz from the team leader since the Chinese New Year. It was originally a infix expression given by user and the program shall be able to return the calculation result. The calculator shall support +-*/()^. and no other function(s) shall be used in this program.

After the console version on Ubuntu 9.10 is completed, I prepared an GUI version on my Realtek 1073/1283 board. The Remote Control is used to input the expression.

Photos as attached !



2010/04/12

(NOTE) Java Gossip: 第一個Java程式

編譯程式
# javac HelloWorld.java

會產生 HelloWorld.class

執行程式
# java HelloWorld

System是放在java.lang的 套件(package) 中,但java.lang中的類別都很常用,無需特別import

參考來源:

"Java Gossip: 第一個Java程式"
- 第一個Java程式 (在「Google 網頁註解」中檢視)

Android

Installation instructions per official website of Installing the SDK | Android Developers (http://developer.android.com/sdk/installing.html) and the other reference page (http://csie-tw.blogspot.com/2008/01/androideclipse.html) makes it easier for us to complete the installation work. 


The HelloAndroid project with Eclipse on Ubuntu 9.10.






















Select [ Window ] - [ Android SDK and AVD Manager ]









check Installed Packages









check Available Packages









To create a new AVD by clicking [ New ... ]















 When AVD sucessfully created...















Click [ Details ... ] to see the details of selected AVD.










Click [ Start ... ] to start the Android Emulator.















Then, it takes times to start up the emulator...

































===========================
Run as Android Application
(Target Platform: Android 2.1 API Level: 7)











=Click bottom ICON ...











= Click the 'Hello, Android' icon,











= And you'll see the console... :)











=END==

2010/04/10

sscanf - parse pre-defined format string

Parse a string with pre-defined format into lots of different variables. The last string shall be able to contain new line character for other purpose.  :)

#include <stdio.h>

int main(int argc, char **argv)
{
   const char *str="123 456 1234567890 1333555777 Line#1 Hello World !\nLine#2 sscanf parse*0 test\nLine#3 End.\n";
   int       a, b;
   long long c, d;   
   char      e[256];

   /// sscanf(str, "%d %d %lld %lld %s", &a, &b, &c, &d, e);
   sscanf(str, "%d %d %lld %lld %[^\001]", &a, &b, &c, &d, e);
   /// \000 is not able to be used because it's null char, end of string
   /// so we use \001 instead
   /// warning: no closing ’]’ for ’%[’ format
   printf("int       a=[%10d], b=[%10d]\n", a, b);
   printf("long long c=[%lld], d=[%lld]\n", c, d);
   printf("\n%s", e);
}


And the result with %s, marked by ///
yenping@Q8400:~/workspace/scanf$ ./a.out 
int       a=[       123], b=[       456]
long long c=[1234567890], d=[1333555777]

Line#1yenping@Q8400:~/workspace/scanf$

Final version, I got what we want.
yenping@Q8400:~/workspace/scanf$ ./a.out 
int       a=[       123], b=[       456]
long long c=[1234567890], d=[1333555777]

Line#1 Hello World !
Line#2 sscanf parse test
Line#3 End.
yenping@Q8400:~/workspace/scanf$

2010/04/03

linux echo command

As I was requested to light up some LEDs on my board, one binary from my colleague was used. But I tried in this easy way...

11111100 (bin) > 0374 (oct)
The last two bits stand for two LEDs.

 box# echo -e \\0374 > /dev/gpio0  

Ubuntu Notification Window + crontab

Hey! Want to get some news from your favorite news websites w/o click your web browser ? Try to do in this way, and hope it will not interrupt your boring work. Ccc...
FIRST, you shall write a simple shell script to parse the news RSS pages from your favorite news website.
$ cat myUdnRss.sh
#!/bin/sh
DL_URL="http://udn.com/udnrss/latest.xml"
#DL_URL="http://rss.chinatimes.com/rss/focus-u.rss"
FILE_SAVED="/tmp/latest.htm"
FILE_PARSED="/tmp/latest.out"
LOGO="/home/yenping/myJob/udn.jpg"

if [ $# -gt 0 ]; then
   DL_URL=$1
fi

if [ $# -gt 1 ]; then
   LOGO=$2
fi

wget $DL_URL -O $FILE_SAVED
##
cat $FILE_SAVED | sed -n -e '/title/p' -e '/des/p' | sed -e 's/CDATA\[/\>/' -e 's/\]/\]*>//g;/ $FILE_PARSED
##cat $FILE_SAVED | sed -n -e '/title/p' -e '/des/p' | sed -e :a -e 's/<[^>]*>//g;/ $FILE_PARSED
##iconv --from-code=Big-5 --to-code=UTF-8 $FILE_PARSED > $FILE_PARSED.2
cat $FILE_PARSED | while read title && read description; do notify-send "$title" "$description"`date +%H:%M` -i $LOGO; done 
------------------------------------------------------------------
Note:
*  sed is used to parse the RSS pages per your demands.
** some pages need to be converted from different encodings.

SECOND, edit your crontab to get, parse, and notify at certain time.
$ crontab -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/yenping/myJob
# m h  dom mon dow   command
#*/1 * * * * env DISPLAY=:0 /home/yenping/workspace/noti01.sh
0  12  * * * env DISPLAY=:0 /usr/bin/notify-send 'Stomach' 'Time to eat !' -i /usr/share/pixmaps/gnome-gmush.png
0  18  * * * env DISPLAY=:0 /usr/bin/notify-send 'Foot' 'Time to go !' -i /usr/share/pixmaps/faces/sunset.jpg
0   *  * * * env DISPLAY=:0 /usr/bin/notify-send `date +\%H:\%M` -i /usr/share/pixmaps/gnome-set-time.png
15,45 * * * * env DISPLAY=:0 myUdnRss.sh http://udn.com/udnrss/latest.xml
00,30 * * * * env DISPLAY=:0 myUdnRss.sh http://rss.chinatimes.com/rss/focus-u.rss /home/yenping/myJob/chinatimes.jpg
------------------------------------------------------------------

FINALLY, when the time being, the parsed news show up in the notify window. :)