Ubuntu 12.04 LTS Beta Is Out

There are supposed to be many changes in the upcoming release of Ubuntu desktop. One notable UI change is HUD (Head-Up Display) where you can type a menu command to get to an application’s functionality without navigation through the menu system. It is useful for users who are experienced with an application and know what they want to get to without menu, sub-menu, sub-sub-menu, etc.

I will need to do a VirtualBox install to play around soon.

http://www.pcworld.com/businesscenter/article/251367/ubuntu_linux_1204_oneups_windows_and_mac_shuttleworth_says.html

How To Keep An Android Service Running

How to keep an Android service running? This is kind of a trick question as the best practice is to not keep an Android service running. If you need to have something done continuously by your app via a service, the service should be started by an AlarmManager at a regular interval and kills itself after the task is done. The reason for this is that a long running service on Android is up to the OS to determine priority and in some cases would stop running. By using this methodology, you are treading lightly since the service does not stay in memory.

Here is some sample code.

Service implementation

public class HeartBeat extends Service {

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onStart(Intent i, int startId) {

		this.beat.run();
		this.stopSelf();
	}

	public Runnable beat = new Runnable() {

		public void run() {
                    // Do something
		}
	};
}

The AlarmManager that starts it.


			Intent iHeartBeatService = new Intent(this, HeartBeat.class);
			PendingIntent piHeartBeatService = PendingIntent.getService(this, 0, iHeartBeatService, PendingIntent.FLAG_UPDATE_CURRENT);
			AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
			alarmManager.cancel(piHeartBeatService);
			alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000, piHeartBeatService);

Now the heartbeat service will start every second and do something and kill itself.

The Current State of Hosting With Dreamhost

I have had a Dreamhost account since 2006 and have various domains hosted on the ridiculous unlimited plan. Back then, their service was very reliable and fairly robust especially compared to some of the other shared hosting services out there. However, over the years their service had definitely degraded culminating to a horrible past few months.

Dreamhost had an unfortunate security breach a few months ago that leaked a bunch of passwords causing a mass reset of passwords. Then their service had been quite unstable with outages lasting a few hours at a time. During the morning of 3/5/2012, many sites were inaccessible along with dreamhost.com being down. They claimed it was caused by a disruption to network connection to one of their data centers.

Over the years, I have moved most of our sites onto cloud server at Rackspace or Amazon AWS. The only sites on Dreamhost are either staging or very low traffic sites that would not be hurt by a few hours of downtime. I will probably keep our Dreamhost account for now, but we just are careful what we decide to put there.

Auto start Sphinx searchd after reboot on Linux

By default, after you install and configure Sphinx, you will find that once your OS restarts, search will not be working. That is because searchd is not setup to auto start. The following will solve that problem.

Create file /etc/init.d/searchd.
sudo vi /etc/init.d/searchd

Copy the following into searchd.
#!/bin/bash

case “${1:-”}” in
‘start’)
/usr/local/bin/searchd
;;
‘stop’)
/usr/local/bin/searchd –stop
;;
‘restart’)
/usr/local/bin/searchd –stop && /usr/local/bin/searchd
;;
*)
echo “Usage: $SELF start|stop|restart”
exit 1
;;
esac

Add execute to the file
sudo chmod -x /etc/init.d/searchd

Register with auto start
sudo update-rc.d searchd defaults

Codeigniter header already sent error using json header

Getting this error when moving from development server to staging server and getting this error.

Severity: Warning –> Cannot modify header information – headers already sent

The error shows up if you are doing all of the following.

1. Change header using

$this->output->set_content_type(‘application/json’);

2. Outputting using echo (which is not recommended by Codeigniter).

3. In php.ini, have output_buffering set very small, like 0.

Solution

There are two solutions to this issue.

1. Increase the output_buffering enough so to buffer your echo. (this is a hack)

2. Recommended solution is to replace echo with CIs built in $this->output->set_output(‘content’) method.

Android making https requests with SSL from GoDaddy – No peer certificate error

Another hair pulling session that all ended well.

Task:

Make a secure call to a server using a httprequest and get the httpresponse for further processing.

Android http request and response:

HttpClient client = new DefaultHttpClient();
HttpGet req = new HttpGet("https://www.example.com");
HttpResponse res = client.execute(req);

Error:

javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

Problem:

The issue is that cert from GoDaddy was installed but not installed completely. An Intermediate cert is required for the server/domain in order to have a fully installed cert.

Reference:

http://community.godaddy.com/help/5238

Codeigniter running into some major growth issues

I have been using Codeigniter for a while on many projects and it had been very useful as it is non-intrusive. Its very small footprint also allows for the extremely good performance on page loads. However, these projects were simply using just the CI core and not implementing any plugins. Some base classes have been extended, but purely specifically for the individual project so not causing any conflict with other code.

Recently, I started building a startup project using CI and would like to employ more plugins do speed up development. Pleasantly surprised, I found that CI had implemented Sparks for searching and installing plugins to CI. Great right! So I implemented an ORM called DataMapper and it was brilliant.

Here comes the reality check. After upgrading from CI 2.0.2 to 2.0.3, everything broke. Why? Because CI changed a lot of methods within its core classes from public to protected. That of course is not actually a bad thing as it was in fact incorrectly implemented before allowing a developer to mess with core functionality too much. However, through researching into these issues, I came to a huge realization that I missed about CI before. CI only allows plugins and developers to modify core classes by extending them into MY_core_class.php. If multiple plugins need to extended the same class, even if they need to overload different methods, it requires some code merging by the developer. If the plugins need to overload the same method in the same core class, that becomes a huge undertaking for the developer to understand what each plugin is trying to do and write merged code that works for both in the same overloaded method.

After that realization, I have determined that CI is fine for applications that are going to use mainly the core classes. If you intend to implement plugins, be very careful understanding what core classes each one will extend. Choose wisely. If those requirements cannot be met, look for another framework.

Code debt accumulating interest

I get into this trap a little too often. I know there is some code that is not written correctly but for the sake of moving along, I ignore it temporarily with the intention of going back to refactor later on. Of course it is not something that is broken, but just poor convention and naming type of stuff. As I build more on top of that, whatever mess that was there before begins to infiltrate into new code through the use of those classes. If I extend upon them, it opens even a greater can of worms.

A friend had talked about code debt before and it speaks so true to these situations. Code debt will incur interest over time if not paid up. The longer you wait, the more expensive the payoff becomes. So just how I like to be financially debt-free, I should strive for code debt-free also.

Citibank web security

Big security hole at Citigroup website

Many may have read about the recent hack into the Citibank’s website that leaked 200,000 user account. At first, one would imagine that it must have been a¬†sophisticated¬†job. Well, the news is just out on how the hacker broke in. It is something anyone could have done by just looking at the URL after they have logged into Citibank and replace the account number with another number to gain access to someone else’s account. It is pure negligence on the part of Citibank’s development team.

I wonder how many people are now looking at their own URLs to determine how much they are revealing.