Top 3 Needs
Recently a friend of mine asked “what’s your top 3 needs right now”. Here is my respond,
Top three things? These 3 things are always true, but as we get into a different stage, they take on a different meaning.
1. Focus. Focus is no longer, heads down and get the release out. Focus now means don’t get side-tracked with the day-to-day but make sure we are marching toward the right goal 6-10 months from now.
2. Cash flow. It’s rather easy to make financial decision when you have absolutely no money. When we are getting money in and need to spend some money, any small financial decision is critical. It’s far easier to spend money than to make them.
3. Growth/Scalability. As we grow, we start taken on different jobs. Starting to be managers rather than workers. Starting to put in process rather than just getting it done.
OK.OK. More concert needs:
1. Legal support. I am going to engage the lawyer soon.
2. Resources. We have been hiring and will continue to do so. Key is the get affordable and effective resources.
3. Slow down. As we gets traction, it’s very easy to think that we are invincible and thus go too fast.
Sze
My First Garage Band recording
This is just the intro to the song I’m trying to learn, but the process is cool so I’m writing it down.
I play the song from my iPhone, and try to play it on the piano.
Once I got the notes correct, I hook up my Mac book to the piano.
As I start playing, notes starts to show up in Garage band:
It records in MIDI with paddle timing and even how hard I hit the keys (emotion). The following is being play back from GarageBand, but it’s almost like me playing. Very cool.
Keep your iPhone apps from crashing
Yes, once again I found myself having to track down some memory issues. Today I tracked down 3 major areas that cause apps to crash. Yes, even if you do all the great Objective-C alloc/release/dealloc you still will be faced with these.
I think most apps have at least 1 of these 3 potential issues so I’m writing down what I did to mitigate the issues and keep the apps from crashing.
So here are the 3, in the order of memory consumption:
1. SQLite – no, there is no memory leak in sqlite, but most people keep one opening connection throughout the app and as you keep creating and freeing prepare statements, it continues to use to memory until the database connection is closed.
2. The Photo Picker – yes, you thought Apple have fixed it in 3.0. They did, but it’s still leaking! If your app takes one or two pictures, then it’s fine. But if your app allows users to potentially take 100 pictures, then eventually you run out of memory, and crash.
3. Network connection. NSURLConnection to be specific. Now-a-days most apps are network enabled and connects to the backend. Some people on the web says the leak is minimal so there’s no need to worry about. Well, if your app (like games) ping the server every second, then a 100 byte leak will soon add up.
And here are my solutions:
1. To deal with SQLite, you have two options. One is to open and close connections frequently. Depends on where you grow up, you may or may not like this option. I happened to grow up in Oracle land, so creating connection every time is something that I tend not to do. What I did is to force temp tables to be created in files instead of memory, thus reducing consumption. Just add the following line after opening a database connection:
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK){
sqlite3_exec(database, “PRAGMA temp_store=1″, NULL, NULL, NULL); //Force using disk for temp storage to reduce memeory footprint.
@interface ZCImagePicker : UIImagePickerController {}
+ (ZCImagePicker*)sharedInstance;
@end
static ZCImagePicker *myInstance = nil;
@implementation ZCImagePicker
+ (ZCImagePicker *)sharedInstance {
@synchronized(self) {
if (myInstance == nil) {
myInstance = [[self alloc] init];
}
}
return myInstance;
}
- (void)dealloc{
[super dealloc];
}
@end
3. Finally on NSURLConnection, just avoid using sendSynchronousRequest. Use the standard async methods you will be fine.
Hope this can help to keep your next iphone apps from crashing.
iPhoneDevCamp DC Demo
For those of you who will attend my presentation in the iPhoneDevCamp tomorrow, please do the following in advance to follow along in the demo:
1. Download exZact Lite from the App Store.
2. Goto the Setting screen, key in the following:
Email Address: ipdcdc (Yes, it’s not really an email address, it will work, trust me.)
Server: zerioninc.com
3. Hit Sync Data With Server
See you all tomorrow.
iPhoneDevCampDC Presentation Overview
I’m going to the iPhoneDevCampDC tonight and tomorrow. I will try to present the following. Hope I can get the vote.
Handling NULL type in the XMLRPC2 package
While working on a client project, I came across an interesting issue in the PEAR::XMLRPC2 package. By default, it uses the xmlrpc C extension in the system. Now that is great but the implementation of that library is so slightly different between different platforms. I found that on Ubuntu, that library can’t handle utf-8 encoding (if you know how to do that, let me know), and in some other system it’s missing all together.
I also found out that you can switch it to use the Php implementation of XML encode/decoding so it should be more cross platform. Great. However, that package doesn’t handle the NULL type, which the xmlrpc extension does!
As we already have multiple projects using this and many databases have NULL in it, I don’t want to do through every project to ensure we don’t send NULLs across, I went ahead and hacked the Php implementation to handle NULL.
Here is what I did (May not be completely correct, if you have better solution, let me know).
STEP 1: Update Value.php
Goto: XML/RPC2/Backend/Php/Value.php. Search for NULL. You will see it explicitly throws an exception. Change the case statment:
case ‘NULL’:
$explicitType = ‘null’;
break;
case ‘resource’:
case ‘unknown type’:
Then a few lines below, yet another switch-case statement, add the handling of Null:
case ‘Null’:
return ”;
default:
That’s it for Value.php. Now any independent Nulls will be handled correctly.
STEP 2: Update Struct.php
To avoid Struct calling encode() on a null pointer, goto /XML/RPC2/Backend/Php/Value/Struct.php. Goto encode(), add two lines:
$result .= ‘<value>’;
error_log(“element is $element”);
if ($element==null) $result .= ‘<string></string>’;
else
$result .= ($element instanceof XML_RPC2_Backend_Php_Value) ?
That’s it.
Now your xmlrpc will return empty string for NULL.
OK, so null is not empty string right? And one should not try to send null through XML? Correct. That’s why on new code, like on the iPhone, I’m coding to avoid sending NULL through XML. But on server code, many many of them, I’m just lazy.
Again, should you have better solution, let me know.
Wordpress Expert!
Yesterday, my co-worker called and said where can he find a wordpress expert and said someone should be able to get it done in an hour. So, I asked, what do you need?
- I have 3 themes that I like, I want to mix them up.
- I want to do wrapper pages just like I could in Joomla.
- and…
Wo, wo, I said, even if someone is very good with Wordpress they can’t get that done in an hour. So, Sze being Sze, said, “I will look into it.”
By 3 pm, I finished:
- Mixing the overeasy theme with videographer theme so some posts uses videographer’s templates.
- Created custom sidebar for different pages
- Created a new wrapper template for wrapper external pages.
Am I a wordpress expert? No. I am just a friend.
UIButton setTitle issue in iPhone OS 3.0
I was working on a client project and come across a bizarre issue. I eventually solved it. Here is the issue, see if you can spot where the problem is.
The following few lines of code generates a button with label “Next” in SDK 2.2.1 but under 3.0, the label is gone.
UIButton *nextButton = [[UIButton buttonWithType: UIButtonTypeRoundedRect] initWithFrame:CGRectMake(183, 30, 65, 25)];
[nextButton addTarget:self action: @selector(nextSettings) forControlEvents: UIControlEventTouchUpInside];
[nextButton setTitle:@"Next" forState:UIControlStateNormal];
[nextButton setTitleColor:[UIColor blackColor] forState: UIControlStateNormal];
[self.view addSubview:nextButton];
Setting up headless Ubuntu with XFCE and VNC (Slicehost)
I recently have to setup a headless Ubuntu box (on slicehost) with GUI support. After search the web I couldn’t find a clean solution. So here it is, hopefully people don’t have to spend as much time as I did.
This solution is based on Ubuntu install on slicehost.
STEP 1 (SERVER):
First, setup your machine’s basic security by following this:http://articles.slicehost.com/2008/4/25/ubuntu-hardy-setup-page-1
STEP 2 (SERVER):
Next, ssh to your box with your admin user (not root) and install xfce and vnc:
>sudo aptitude install vnc4server
>sudo aptitude install xfce4STEP 3 (SERVER):
Now we want to run a quick test on the vncserver:
>vnc4server -geometry 1024×768It should ask for a password, type in something you can remember, this will be your vnc password.
You should see something like:You will require a password to access your desktops. Password: Verify: xauth: creating new authority file /home/adminA/.Xauthority New 'HostA:1 (adminA)' desktop is HostA:1 Creating default startup script /home/adminA/.vnc/xstartup Starting applications specified in /home/adminA/.vnc/xstartup Log file is /home/adminA/.vnc/HostA:a.logAll seems fine. Now kill vnc:
>vnc4server -kill :1STEP 4 (SERVER):
Setup vnc to start xfce:
>vi ~/.vnc/xtartup (or use your favorite editor)The file should look lie:
#!/bin/sh # Uncomment the following two lines for normal desktop: # unset SESSION_MANAGER # exec /etc/X11/xinit/xinitrc [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources xsetroot -solid grey vncconfig -iconic & xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & twm &Now change the last couple of lines to:
xsetroot -solid grey vncconfig -iconic & # xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & # twm & startxfce4
Server setup is now DONE!
STEP 5 (Client):
If you have followed the setup in Step 1, your iptables should be configured to open only http, https and ssh. Instead of opening port for VNC, we will do ssh tunneling. (Slightly more hassle but much more secure):
On your client machine (Windows, Mac, etc), with your favorite ssh client:
(assume you setup your ssh port in step 1 to 4567, hostA is the server name, adminA is the username)
>ssh -p 4567 -L 5902:localhost:5901 hostA -l adminA
On Putty (PC),
Goto the Tunnels setting inside Connection->ssh
Source Port : 5902
Destination: localhost:5901
Hit Add. The following should show up in the Forwarded ports list:
“L5901 localhost:5901″
Once logged in the server, start vnc:
>vnc4server -geometry 1024×768
Then leave the session running. You are almost done.
STEP 6 (Client):
Now just start your favortie VNC client and connect to: localhost:5902
Note because we are using SSH tunnel, VNC to connect to localhost instead of your server. Port should be 5902 and not 5901. SSH will do the rest.
XFCE should now show up.
STEP 7 (Client)
Yes, there is a Step 7. That’s the clean up. We don’t want VNC to be running all the time so when you are done, before killing the ssh session, kill VNC:
>vnc4server -kill :1
From now on all you need to do is to repeat Step 5-7.
Enjoy!
Vote Report Wins the Golden Dot Award
Yesterday I went to the Politics Online Conference in Washington D.C. for the Golen Dot Award. Since so many of my friends ask “What is that?”, I’m going to talk a bit about the project and the award itself. I will then post a follow-up blog on my experience yesterday in more detail.
The award is the Golden Dot Award from the Institute for Politics, Democracy, & the Internet at George Washington University. Every year, they organize the PoliticsOnline Conference in Washinton D.C. and announce the best internet projects related to politics. This year, our project, the TweeterVoteReport and Inauguration Report, won the Best Mashup category.
The projects, VoteReport and InaugurationReport, are Crowdsourcing Political Journalism projects. In plain English, it’s using social network technology and allows the public to document political events. During last year’s election and the inauguration in Jan, we use the same technology and allow people to share their experience. The result is huge amount of data (text report, photo, audio, video) with geo location information. We collect data through Twitter, SMS, Filckr, Youtube, iPhone and Android. We then open up this stream of data and allow any media outlet to mashup in anyway they want. The project is completly open-source. The project was organized by NPR, Tech President, American Univeristy and CBS News. There are over 20 developers participated in these projects, including Sanford Dickert from Contagious Conversations, Dave Troy from TwitterVision, Andrew Turner from GeoCommons, Sze Wong from Zerion Software, and Nathan Freitas. Full contributor list of the vote report project can be found here.
You can read more about the projects in my pervious blogs or the following links:
http://techpresident.com/blog-entry/vote-report-wins-golden-dot
http://afine2.wordpress.com/2009/04/13/twitter-vote-report-goes-to-india/
http://blog.twittervotereport.com/
http://www.npr.org/blogs/inside/2009/01/inauguration_report_is_live.html
http://www.npr.org/templates/story/story.php?storyId=99395388
http://www.inaugurationreport.com/
Like I said on the Panel yesterday, it’s been a great honor working on this project. From both the social data collection and development collaboration perspectives, this project was a great success.



