Posted by: Tharindu | April 5, 2011

Bloodless Medicine iPhone App (iAvoidBlood)

I started with few little iPhone apps at Silk. Blood App (simply termed) was one of iOS apps that I worked on during my stay at Silk. It’s later decided to name as iAvoidBlood to highlight its core function. This application is a collaborative educational project which promotes Bloodless Medicine. Bloodless Medicine refers to emerging clinical strategies for medical care without allogeneic blood transfusion and is said to be a well-defined area in Blood Management. The circular of information distributed with Blood and Blood Components recommends that all physicians be familiar with the alternatives that are a part of Bloodless Medicine.

Download iAvoidBlood on Apple Store

Blood App include three utilities named Evaluation (Animated Blood Calculator), eBlood Card & Blood Centers (Geo-Localization). In addition, App include detailed informative sections describing Blood (components of blood), Blood Transfusion, Transfusion Alternatives, Ethics and Glossary.

Evaluation utility – adds an animated calculation showing Final HT value calculated using patient or user’s Gender, Estimated Blood loss, Initial HT & Transfusion Threshold.

E-Blood Card – provides users to keep his preferences for accepting whole blood or its components. Users can share their e-blood card via emails.

Blood Centers – shows the nearest Blood Centers marked on a Google Map using iPhone Map Kit framework. Using Google Geo-coding API users are provided a way to search for nearest blood centers from any location. Data for the blood centers are read from silk web services. Even user could look for the route for Blood center and its details.

Transfusion Alternatives – provides comprehensive detailed section that describe the top to bottom details on Bloodless Medicine.


Following is a quick video of the Blood App.

Following are some screen shots for the app.

I was needed to somehow add VoIP into my Level4 Project. It made me search all over Google for some existing work. And found this project Siphon that enables SIP voice calls. There are few guides on Siphon Wiki, still I was stuck with linking issues for nearly a month. After trying lots of hours I gave up all that trying to compile for iPhone 3.0. Again yesterday, I have been trying to compile free open source project Siphon to run on iPhone Simulator and iPhone all day. It was really difficult task having the Siphon team done lots of effort on making an Open Source project, still just to compile it. My lack of knowledge in C++ or C made this even harder. Finally lots of hours invested, days wasted now I have it running on my iPhone. So may be this will help some newbie on low level coding (C, C++) other than Objective-C to run this amazing app compiled on your iPod or iPhone. Having credits on your SIP account you may convert your iPod into an iPhone on WiFi.

Siphon Project on Google Code

Siphon has wiki pages saying how it could compile to iPhone OS 2.x but still it seems to be not enough and I couldn’t make it success by any means unfortunately.

Steps to follow for Newbie.

1. We need to compile and build required libraries from compiling PJSIP project first. There are few things I did wrong here. I have compiled for Device and tried to run it on Simulator without writing my own configure script. Trying to use same one on PJSIP Then I got so many linking issues that I couldn’t understand WTF is this.

2. Let’s compile PJSIP for iPhone first and build libraries required and then to Simulator as well with a more change to configure script. Before going into Siphon project.

2-1. Download PJSIP source code from here. Now it includes configure script for iPhone that you need to edit once for iPhone again for Simulator.

svn co pjproject

2-2. Create a new file pjlib/include/pj/config_site.h.  Add following code into it.

#include <pj/config_site_sample.h>

2-3. If you go to pjproject folder, you will see configure-iphone script. Need to edit this to compile for your desired iPhone SDK. Open this with your favorite Text editor, mine was TextWrangler.

$ edit configure-iphone

2-4. Hard code the $DEVPATH and $IPHONESDK. So you don’t need to export those environment variables. If you not specify $IPHONESDK it will be the OS default. ex.


2-5. Now you can easily build the libraries that will be stored in lib directories of folders, pjlib, pjlib-util, pjmedia, pjnath, pjsip, third_party. Check once again about your configure-iphone script for correct paths and compile and build libraries using following commands simply.

$ cd /path/to/your/pjproject/dir
$ ./configure-iphone
$ make dep && make clean && make

2-6. Now you have libraries for iPhone. Make a copy of pjproject folder and rename it to pjproject_sim. Here we are going to have our iPhone Simulator libraries built

$ cd /path/to/your/pjproject_sim/dir
$ edit configure-iphone

2-7. Hard code the $DEVPATH and $IPHONESDK. This time they should the paths for Simulator SDKs. And one more change here, that I was missing. caused all sorts of problems.

2-8. Search for 'ls -d ${SDKPATH}/usr/lib/gcc/arm-apple-darwin*' in configure script and replace it with following that way you could build correct libraries for simulator.

ls -d ${SDKPATH}/usr/lib/gcc/i686-apple-darwin*

2-9. Great now you have all libraries needed in folders, pjproject and pjproject_sim.

3. Now let’s go and checkout siphon project.

svn checkout siphon

4. There was a compilation issue in Siphon code, that you could ignore by doing a little trick, I don’t know whether its right or wrong. But it works perfect. Otherwise, project didn’t compile for me. Open Siphon2 folder iPhone project on iPhone then go to call.m. Search for PJSIP_CRED_DATA_MJ_DIGEST and replace it with PJSIP_CRED_DATA_DIGEST.

5. Now add all the library .a files in following folders to the project. pjlib, pjlib-util, pjmedia, pjnath, pjsip, third_party.

6. Now follow the screen shots carefully. If you build for simulator use simulator library files (pjproject_sim folder) and include files to library and header search paths, other wise use libraries & include files in pjproject folder.

Make a duplicate of Debug to run in iPhone, let debug to be used by used by simulator libraries.

Let’s add Library Search Paths & Header Search Paths for siphon target. Following are examples of my locations for simulator. For device its the location to pjproject folder we built and stored our library files for Device.

Change CYDIA=0 in Preprocessor Macros

7. Add the Settings Bundle for your project as given in this following link. It works perfect then.

Siphon and Settings Bundles

8. Now you could run it on your iPhone or Simulator. Use a free SIP service to create SIP accounts to test the app. I have used, Sip2Sip


Following link contains very useful information updated about how to get PJSIP compiled for iOS. Please refer to the pjproject Wiki page below.

Building for Apple iPhone, iPad and iPod Touch

* IMPORTANT: I had to follow additional step to get things done for iOS Simulator. before run ./configure-iphone script

export DEVPATH=/Developer/Platforms/iPhoneSimulator.platform/Developer
export CC=$DEVPATH/usr/bin/gcc
export CFLAGS="-O2 -m32 -miphoneos-version-min=3.0" LDFLAGS="-O2 -m32"
Posted by: Tharindu | June 16, 2010

How to add Syntax Highlighting to Default Mac Terminal

I was wondering why Mac Terminal doesn’t have nice color highlighting that all other Linux based OSs have. Suddenly realized that it should be enabled with few little things to get it done on Mac OS. Follow the few steps to make it highlighted. Before it was enabled my Mac terminal didn’t look any better as my Ubuntu terminal. It was like below.

1. Create a file named .profile if it doesn’t already exists. Add the following line for that file.

alias ls='ls -G'

This will add higlighting when you use, ls commands to list files and directories, better than looking at black color all the time.

2. Do the following to add highlighting for vi editor.

:~ cd /usr/share/vim/
:~ sudo vim vimrc

Add the following code after the line with ‘set backspace=2’

set ai                  " auto indenting
set history=100         " keep 100 lines of history
set ruler               " show the cursor position
syntax on               " syntax highlighting
set hlsearch            " highlight the last searched term
filetype plugin on      " use the file type plugins

" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if ! exists("g:leave_my_cursor_position_alone") |
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif |
\ endif

Save the file with Esc + :wq. Now your vi editor will show source files with some highlighting as well.

OK. Now it looks far better with some colors after this.

Posted by: Tharindu | June 9, 2010

How to resume a broken XCode Download using Safari

It has been a pain for me to make this 2.x GB XCode download successful with my slow ADSL connection. When I first tried, it was broken at over 1 GB then again I had to start over again. Finally with help of apple forums and Google I was able to stick to a successful method. In this case you have to start your download in Safari, and if its broken you can resume it anytime by following a little trick.

1. Login with iPhone Developer account in Safari Browser and start your download. In case you break the download, which would definately happen in a slow connection that takes around 10 – 12 hours to complete.

2. Once it’s broken Right click on broken download and click Show In Finder

3. You will see a file with ‘’ like some thing. Right click on that and click on ‘Show Package Contents’

4. Safari keeps a Info.plist file with download progress that is the one we are going to use for our purpose. Open it with a text editor and notice there’s key value pairs. Notice the key value pairs below.





5. Now you can’t resume this download, that has lots of bytes already downloaded.Do this to use the already downloaded file.

6. First start a new download again in Safari and stop it. Then again go to finder and ‘Show Package Contents’ of this new download.

7. Here also you will see an Info.plist file open it and copy the Download Entry Identifier value.

8. Hay now you are done, paste this to the old Info.plist file. Go to Safari you will see that your old download is now resuming. Saves a lot of time for you on a slow Internet Connection.

Have fun with XCode then.

I wanted to install tomcat, MySQL and then run a jsp application that connects to a MySQL DB on tomcat in Mac OS X. I have been using Mac OS for more than a year still only used it for mainly iPhone Development work. For other work on development I mostly used my Ubuntu OS at home PC. So I started all this from searching in google like ‘how to install tomcat on mac os’ and then ‘how to install mysql on mac os’ and then ‘how to set environment variables on mac os’ so and so whole day to run my app on tomcat at my MacBook. So I thought it would be useful to blog all these steps together for someone to finish this little easily. I will blog where you should refer for each step and after finishing you can come back here to see what next to do. ok great, lets just remind how i started. ha ha

1. Installing Tomcat – I have installed apache tomcat 6.0.24 exactly following same steps given in following article by Apple, eventhough it describes steps on installing 4.0.1 it is the same for later version of tomcat as well. It’s just a matter of downloading the tomcat distribution. You don’t need to complete the whole process. Just stop when you see tomcat up and running. I stopped my self at the end of ‘Starting and Stopping Tomcat’ section.

Java and Tomcat on Mac OS X

2. Install a text editor that can run from terminal (Optional). – Usually vi command is the preferred way of editing text files on Unix OSs. But for Mac OS X you should try with Text Wrangler. it has easy to install dmg file and after install Go to Menu TextWrangler -> InstallCommandLineTools… Now you can use ‘edit [filename]’ from command line to open up text files you want to edit instead of using vi. This looks much pleasant when you edit files.

3. Setting up Environment Variables – $CATALINA_HOME, $JAVA_HOME, $ANT_HOME. To setup environment variables create a file named ‘.profile’ in your home directory or edit it if it’s already there. Open it up with TextWrangler or use vi to edit it. Now add tomcat home, java home and ant home like below.

>edit .profile
[edit the file to set values and save]
>source .profile

export JAVA_HOME;
export ANT_HOME;

Important points here: Usually Mac OS comes with Java and default Java Home directory is located at /Library/Java/Home. In case you want to know where your ant home is. Type command ant -diagnostics then scroll up to see where ant.jar is in command line output. You know where ant is then.

4. Installing MySQL on OS X – This is pretty easy with Mac OSX Distribution you could download at MySQL web site. You can easily install MySQL with installer and then follow the instructions in Read Me to start MySQL server to work with.

Download Mac OS X MySQL Server Distribution

Important points here: Once you setup alliances in ~/.bash_profile as in README, To setup a root password use following command mysqladmin -u root password passwd

5. Setting up tomcat to connect to MySQL – you have to add the mysql-connector jar file to library folder and also edit the context.xml file in tomcat server. Read the detailed steps in following article to understand it fully.

MySQL DBCP Example on tomcat 6

Now you can run your JSP or Servlet application without any issues on Mac OS within tomcat server with MySQL databases.

Posted by: Tharindu | April 19, 2010

How to create iPhone Photos like thumbs in an iPhone App

I wanted to create image thumbnails or thumbs of images in an iPhone application. For this I have searched over the web for a small sample code to do this. I have found few but they all didn’t seem to be the right way. They didn’t work perfect as how Apple does it. Some methods introduced distortions and some only scaled the image. Therefore, finally I thought of implementing it my self. It’s actually a very simple algorithm or process to implement. A combination of cropping and scaling in one method.

1. Check UIImage width and height we want to scale first. If both width and height are same no need to crop. If width is bigger then we need to crop image to a ratio of its height. And we determine the xposition to crop the image by subtracting height by its width and then dividing answer by two. The same process done other way if height is bigger than width taking width as the cropping ratio.

2. Now we have a square image that we can scale to our thumb size. This scaling now will not include any distortions to the image.

Below is the code segment that does it nicely.

/** generate thumbnail version of given image to show in properly **/
- (UIImage *)generatePhotoThumbnail:(UIImage *)image withRatio:(float)ratio {
   // first crop to a rectangle and then scale the cropped image to ratio
   CGRect cropRect;
   if (image.size.width == image.size.height) {
      // height and width are same - do not crop here
      cropRect = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
   } else if (image.size.width > image.size.height) {
      // width is longer - take height and adjust xgap to crop
      int xgap = (image.size.width - image.size.height)/2;
      cropRect = CGRectMake(xgap, 0.0, image.size.height, image.size.height);
   } else {
      // height is longer - take height and adjust ygap to crop
      int ygap = (image.size.height - image.size.width)/2;
      cropRect = CGRectMake(0.0, ygap, image.size.width, image.size.width);
   // crop image with calcuted crop rect
   CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], cropRect);
   UIImage *cropped = [UIImage imageWithCGImage:imageRef];
   // scale the image to ratio to create proper thumb
   NSData *pngData = UIImagePNGRepresentation(cropped);
   UIImage *myThumbNail    = [[UIImage alloc] initWithData:pngData];

   // begin an image context that will essentially keep our new image

   // now redraw our image in a smaller rectangle.
   [myThumbNail drawInRect:CGRectMake(0.0, 0.0, ratio, ratio)];

   // make a copy of the image from the current context
   UIImage *newImage    = UIGraphicsGetImageFromCurrentImageContext();
   [myThumbNail release];
   return newImage;
Posted by: Tharindu | February 11, 2010

How to integrate Twitter to Google Buzz

It’s very cool that you can just publish your twitter feeds directly to Google Buzz..

You can see a very small link right to your profile name called “connected sites” .. go there and add your Twitter profile feed.. so you don’t need to buzz in Google 🙂

Google Profile Connected Sites small link

But this personally feels like messy for me having loads of buzzes in Personal email

Posted by: Tharindu | January 14, 2010

SriLanka Insight 1.1 Update Available

I have a problem of having broken links for my iPhone application after few days. I had to update a quick release since without remote server available, it wouldn’t be any use for users. New version includes 60 images of beautiful sights from SriLanka. I released an update on 11th January, and surprisingly within less than 3 days it was on AppStore. So it’s certainly a great improvement of Apple Application Review process.

Still I think I should do few improvements to version 2. What I expect to do is make application independent of remote server, rather it must load images from what ever server I prefer by reading a file at remote destination. I would cirtainly want to do this in my available time for next release. This way I expect to make application load any number of images without changing any single line of code at client.

Posted by: Tharindu | December 23, 2009

SriLanka Insight iPhone Application

I have been working on implementing an iPhone application that I wanted to show up most beautiful images from SriLanka. And I have worked on this from the first day I got my MacBook. Eventhough, I am still not a registered Apple iPhone developer but I wanted my application to be in AppStore, first day I have finished development. To publish my application therefore I have asked for my friend in Switzerland, who was very generous to my request. I knew Apple would take at least two weeks to publish it from my previous experience on hExpense application submission. But it was unbelievably much faster this time. It took nearly less than six days, which was a significant improvement with Apple Approval Process from my first application submitted on behalf of hSenid Software Interational. That took more than 2 weeks to be approved by apple. And yet still there was a slight delay to appear the application in iTunes even after it was shown as ‘Ready to Sale’ status with iTunesConnect. But it’s acceptable when it compared to my initial experience.

And SriLanka Insight is a pretty cool application that brings an iPhone Photos like application with 52 SriLankan images hosted remote. You can experience auto rotations, pinch in-out to zoom in-out images, swipes to move between srilankan images. And also you have the ability to share these images with your friends within the application. Until iPhone OS 3.0 SDK we had to leave the application to add this functionality. But now it’s quite nice that we could integrate it within our application rather giving responsibility to iPhone Mails application. Additionally you could send comments directly to me, within the application on how you would like it to be improved. At the same time, you could save the images to iPhone Saved Photos album if you want. Therefore, I think it could be a cool application for SriLankans as well as who likes SriLankan sights just to experience that completely free application.


Review SriLanka Insight at Apptism

Posted by: Tharindu | December 3, 2009

How to install Sinhala unicode for Mac

I was looking for how to install sinhala unicode fonts for Mac. When I initially checked out about this I could not find this details from Siyabas site by ICTA where it has all other information regarding installing Unicode fonts for different Operating Systems. For OS X (Leopard, Snow Leopard) site did not contain any information. Then through wikipedia article on Sinhala Font Guide, I was able to get a link to download Malithi web sinhala unicode font designed for Mac. So I just thought of posting this few simple steps on how to have Sinhala unicode running for a Mac. But still with some rendering problems may be

  • Download Malithi web font for Mac from here (.ttf)
  • Copy the file to /Library/Fonts folder simple as that

At this point at least now we can see some sinhala web pages but still with some rendering issues for letters with ‘combu’ some times. I will add it here if I find a better solution than this later.

Download Mac Compatible Kaputa font

There’s Google Noto Sans Sinhala font to be downloaded as well. This font was released as a result of Google’s attempt to make free fonts available for all languages.

There seems to be a really well made Sinhala font designed for Mac. It is mac version of Bhashitha Font. Download Mac Bhashitha font.

Also you could download Unicode equivalent FM Fonts from Unicode equivalent FM Fonts

Also you could download FireFox RC2 with Sinhala for Mac.

Update on July, 2021 –

How to type in Sinhala on Mac?

macOS supports Sinhala Unicode by default. To easily type Sinhala Unicode on macOS 10.15 (Catalina) or later, you could use Sanhinda Sinhala Typing Pad downloaded via mac AppStore. The typing pad transliterates English to Sinhala Unicode Realtime and could be easily copied using keyboard short cut ⌘ + P.

« Newer Posts - Older Posts »