Tuesday, July 27, 2010

a script to replace extention of files

Suppose the file extension is "foo".


#!/bin/bash

for f in `find . -name "*.foo" -type f`
do
newname=`echo "$f" | sed "s/\.foo$//"`
mv $f $newname
echo "mv $f to $newname"
done

exit 0

Monday, July 5, 2010

vmware fusion -- network no connection

The following tip can fix "network bridge device on /dev/vmnet0 is not running" failure.


$ sudo /Library/Application\ Support/VMWare Fusion/boot.sh –-restart

Wednesday, June 30, 2010

unlock android emulator

$ adb devices (to find port number 5554)
$ telnet localhost 5554
event send EV_KEY:KEY_MENU:1

ubuntu 10.04 notes

1 install vmware-tools

$ uname -a -> to find linux header version
$ sudo apt-get install linux-headers-2.6.32-21-generic
$ sudo apt-get install build-essential
$ sudo ./vmware-install.pl


2 build android 2.2

$ sudo apt-get install gcc-multilib g++-multilib zlib1g-dev gperf
$ sudo aptitude install libncurses-dev
$ sudo apt-get install bison flex git-core curl
$ sudo apt-get install openjdk-6-jdk
$ repo init -u git://android.git.kernel.org/platform/manifest.git -b
android-2.2_r1
$ repo sync
$ vim ./build/core/main.mk change 1.5 to 1.6
$ source ./build/envsetup.sh
$ lunch 1
$ make -j8

Wednesday, March 17, 2010

learning iphone programming

I start to write some code for learning iphone programming especially objective-c.

The first example shows here is an example to call ANSI C API (that is the first thing I want to figure out in the object-c environment).



/** @find_date generate date string from current time
*/
- (char*) find_date
{
static char date_str[80];
struct tm * my_tm = NULL;
char *month_str[12] = {
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
};
time_t time_val;
time_val = time(NULL);
my_tm = localtime(&time_val);
sprintf(date_str, "%s%02d", month_str[my_tm->tm_mon], my_tm->tm_mday);
return date_str;
}



And here is the call to find_date. (convert to NSString from C-String)


{
char date_str[80];
sprintf(date_str, "modified: %s", [self find_date]);
label2.text = [NSString stringWithCString: date_str];
}



Now another example, with given date as input, open a file and read the data from the file, returns the buffer which contains the file content.


- (char*) init_jk_quote: (char*) date_str
{
FILE* fp;
char* quote_buf;
int length;

fp = fopen(date_str, "r");
if (fp == NULL) return NULL;
fseek(fp, 0, SEEK_END);
length = ftell(fp);

quote_buf = (char*) malloc(length);
if (quote_buf == NULL) {
fclose(fp);
return NULL;
}
fseek(fp, 0, SEEK_SET);

fread(quote_buf, sizeof(char), length, fp);
fclose(fp);
return quote_buf;
}
- (void) free_jk_quote: (char*) quote_buf
{
if (quote_buf)
free(quote_buf);
quote_buf = NULL;
}




And the call to the functions is demonstrated here.


{
char* quote_text;


quote_text = [self init_jk_quote: "/tmp/March17.txt"];
if (quote_text == NULL || strlen(quote_text)== 0) {
label3.text = @"not supported!";
}
else {
NSString* mystring = [NSString stringWithCString: quote_text];
label3.text = [@"my quote: " stringByAppendingString: mystring];
}
[self free_jk_quote:quote_text];
}




I think I need to break my habit of writing in C, and convert it to objective-c, so how to convert the above functions in object-c style? That is mainly something I need to learn.

Monday, March 15, 2010

eight steps to become an iphone developer

Here is the link on how to become an iphone developer.

In brief:
1. buy a mac (done)
2. down the sdk (done)
3. learn objective c
4. start writing something
5. sign-up as an official developer ($99 done)
6. prepare for a few weeks of work
7. submit your app to Apple
8. adapt, market and survive!

It did not mention a iphone but I already bought it. I would spend some effort to become a iphone developer. Learning is important to a programmer, just like several years ago, I learn the development on Linux, and later found that it is useful in my career. I did work on Linux platform. Mobile is a big market as I knew, so I can gain some skill here for the purpose of surviving.

Thursday, February 25, 2010

patching the code using cvs

I have blogged this and this,

But I would use the following command to create a patch and apply the patch.





$ cd /devel/foo
$ cvs diff -uNa > patch.txt
...
$ cvs co -r z_markc_-22jan2010 foo
$ cd foo
$ patch -p0 < /path/to/your/patch.txt


In creating a patch, "-a" is used for added code if needed.

Monday, January 4, 2010

merge library

1. extract the libraries foo and goo.


$ mkdir t
$ cd t
$ ar x ../libfoo.a
$ ar x ../libgoo.a


2. Prepare "Makefile.t"

all:
$(CROSS_COMPILE)g++ -shared -o libbar.so ./t
$(AR) -rcs libbar.a ./t/*.o


3.generate the new lib


$ make -f Makefile.t