Category Archives: Hobbies

Picasso and null path to image

Found something very odd when programming my Android mobile app today. I am aware that I should not provide a null path for Picasso to load. Hence defensive statements in my code to make sure that Picasso would not get to load a null path. But somehow my app was still crashing, with the following error:

    java.lang.IllegalArgumentException: Path must not be empty

And the error was pointing to the line where the Picasso call was located:

Picasso.get().load(“null image path”);

Even when this line would not be run, which I have checked, it was still giving me problem. Turns out that my defensive statement allowed non-null image path to happen first, as below:

if (imgPath != null || !(imgPath.isEmpty()) {
    Picasso.get().load(imgPath).into(imageView);
} else { 
    Picasso.get().load(placeholder).into(imageView);
}

If I swap the defensive statement around, such that imgPath == null is checked first, then my app will run okay. Very odd. Anyone kind enough to explain to me what was that about?

Adding data to Firebase using custom objects

I’m fairly new to using Firebase, and their nosql type databases. It did take me some time to understand how data is arranged, with collections and documents.  When developing my application, in Java, I created a class for storing data, a.k.a. POJO. What is unclear from the Firebase documentation is how the fields in a document will be named.

There is a line that says this: Each custom class must have a public constructor that takes no arguments. In addition, the class must include a public getter for each property.

I initially did not pay attention to this public getter, i.e. a get method for each property in my object. Of course it is good practice to always create all the methods when creating a class. I was lazy, thinking that I only add them when I need to use them. Then came the interesting bit, where even after all the properties in my object had been initialised, and added to the Firebase document, some properties went missing in the database. I found it very odd. I initially thought that the fields in a Firebase document would be added according to my Java class, and following the naming I used in my class. But that was not the case. Dug a bit deeper, and it follows that if my getter method is getImgPath(), then the field in my Firebase document will become imgPath (note the upper case for “I” becomes “i”).  And without a getter method for property, then you will have a missing field in your Firebase document!

Hope this helps for those who are wondering how a document in Firebase is populated using custom objects.

Migration of WordPress website to another web server

Okay, I have done this before, over 10 years ago. Here I am doing it again. There are plenty of guides around on the Internet that can help with this process. I am just making a note here:

  1. Zip up the whole document root directory. On CPanel’s File Manager, select all and then click on “Compress”.
  2. Export mysql database that corresponds to the WordPress website, and say you name the file as wp-db.sql. You can zip the file to make it smaller if you want.
  3. Transfer these two zip files to the new webserver, e.g. /var/www/html. You can use wget to copy the files from existing web server to the new web server.
  4. Unzip the files.
  5. At this point, you won’t be able to access your webpage yet. Because the mysql database records, from your website, need to be placed into the new mysql server. This requires that you create a new database on your mysql server. To do that run this command.mysql -u root -p

    Type the master password, then type the following command.

    CREATE USER ‘wordpress-user’@’localhost’ IDENTIFIED BY ‘your_password’;

    Here replace wordpress-user and your_password with your username and password. You can refer to wp-config.php for the username and password you have used for accessing your WordPress mysql database in the previous set up.

    Run this command to create a new database.

    CREATE DATABASE ‘wordpress-db’;

    Here replace wordpress-db with your database name, which again you can refer to wp-config.php in case you want to keep the same name.

    Now grant full privileges for your database to the WordPress user that you created earlier.

    GRANT ALL ON wordpress-db.* TO ‘wordpress-user’@‘localhost’;

    Now flush the database privileges.

    FLUSH PRIVILEGES;

    Exit mysql

    exit

  6. Import the mysql database, that you unzipped earlier, into the new mysql server’s wordpress-db database you just created.mysql -u root -p wordpress-db < wp-db.sql
  7. To allow WordPress to use permalinks and .htaccess file run this command.sudo nano /etc/httpd/conf/httpd.conf

    Find the section that starts with <Directory “/var/www/html”> using the scroll key of your keyboard.

    <Directory “/var/www/html”

    AllowOverride None

    ….

    </Directory>

    Here replace “None” with “All”

    AllowOverride All

    Then save and exit the editor.

  8. You should now be able to access your website by typing in the IP address of your new web server. Next the DNS name servers need to be updated to point to the location of your new web server.

Transferring web hosting service

It’s been a while since I last blogged. This time it’s about time to renew my web hosting service. At this current economic climate, USD200 for two years of service seems like a lot now. I have gone through web hosting service provider change for a number of times. But I still managed to get the DNS wrong, somehow. It should be a simple straightforward copy from the previous hosted zone file to the new service.

Okay, for my own record, as well as for others as well I guess, I have complete control over my web server now. I always have about two websites to manage. But as I figured out lately, it is called name-based virtual hosting that I have been using. So web access to my website will be based on domain name, not IP address. Because I have more than one websites hosted based on just the one IP address, accessing the IP address would not return me the desired webpage. The virtual host configuration is such that access, based on domain name, will get served documents from the document root as stated in the configuration. Okay this is clear to me now.

However, when managing my hosted zone, for domain name translation, I used a CNAME record for www (i.e. www.mylearningdiary.com) that pointed to the IP address of my web server.  That gave me a NXDOMAIN error, or non-existent domain error, everywhere. I initially thought that was to do with propagation delay after switching the DNS, at the registrar, to point to the new domain name servers. This is well known, so I patiently waited, and checked, and tested. But still couldn’t access my website. After a day or two, I trawled the Internet, and then started using dig, a network administration command-line tool for querying the DNS, which I have used before long time ago, to check what was going on. Dig is more helpful than nslookup, that it not only showed me the error, but it also showed me that I actually got the IP address returned when querying for the www CNAME record. That was useful enough for me to know that my DNS servers were responding to the CNAME query, just not good enough for me to reach my website. Instead of IP address, the domain name, i.e. mylearningdiary.com, should be used for the CNAME record.

Now the website is finally back up running again,  I need to try setting up the mail forwarding. Hopefully without me having to set a mail server.

A cheap Hoegaarden

Having touched on beer drinking in one of my earlier posts, I’m now curious how much a bottle of Hoegaarden actually costs in a supermarket. Here you go, 5 bottles of Hoegaarden, with a free glass, retailing at RM69.95 at Tesco.

Hoegaarden
Works out that it’s just under RM14 a bottle. Whereas at Marianis, during happy hour, it’s just RM12.80++. So it’s about the same price drinking at home or at Marianis! All the more reason to drink there before they move to Greentown!;)

Avoid Berkshire Appliances for repair work

Okay think I’ve given Berkshire Appliances enough time to get back to me to explain why he stood me up yesterday. I left voice mail, called couple of times, both his mobile as well as the landline number on his website. Nope, he didn’t bother. I’m not going to bother and post this negative review of the service I received too. To be fair he sounded like he’s quite competent when I phoned him up. But it is of no use if you are not reliable and waste customers’ time. Not everyone can afford to sit at home and wait for you to turn up to do a job. I had to wake up real early in the morning so I could get off work early to make the appointment. It would have been nice he phoned and be apologetic about his absence, for whatever reason. But nope, absolutely nothing from him since. All these talks of economic recession and unemployment, don’t seem to affect these repairmen. With attitude like this I really don’t mind him going out of work.

Replacing bicycle chain and freewheel

It’s that time of year again. I seem to be repeatedly doing the same thing without learning. Found that the chain on my bike was slipping, replaced with a new set of chain, and then found that it was slipping even more. Sounds familiar. Checked my blog, and this happened just less than four years ago. Because I thought I have “just” replaced my freewheel, I thought it is the front chainset that needed replacing instead. Went to the bike shop, luckily this time it’s just down the road, the shopkeeper told me that every time I replace my chain I should replace the freewheel as well, otherwise the chain will slip. Looks like I have worn out the freewheel once again. Probably should have just replaced the chain every one or two years. As it turns out that it is such an expensive exercise having to replace the chain and the freewheel together every time! But I seem to remember my colleague suggested to me before that a general guideline of his is to replace the chain every 5000 miles. Looks like since I don’t really take care of my bike, and don’t keep track of how many miles I’ve covered, I should just come up with my own rule and replace the chain every one and a half year instead. OK, this post shall mark the day on which and I replaced the chain. Let’s see if I can remember…

Reading my own diary

Today my colleague was looking for information on how to take off the cassette from his rear bicycle wheel. Then I remember that I have written something on here about the differences between cassette and freewheel. What a great idea keeping a diary like this! I can easily retrieve the information too, probably quicker than using Internet search engine.Sometimes it’s not about me writing something more useful than what already have been written elsewhere. It’s just that some times it is quite nice reading what I’ve written some time ago as well. Does remind me of what I’ve been up to at that moment in time. And interestingly I was somewhat amazed after reading my post again, as I could not remember most of what I had written, and that was only 2 years ago! Think I will make a conscious effort to keep blogging here, despite spending more and more time on Facebook lately. Shame on me (I know!).

Horse manure as fertiliser

We finally got our allotment after what must have been a 2 years queue. This is how the allotment area looks like (not how our plot of land looks like though 🙁 at least not yet). We would certainly like our plot to look somewhat like that, but it will almost certainly requre a lot of work. Now that the little one is coming out quite soon, I really wonder if we can keep the land at a respectable state!Anyway I went to a stable where my colleague keeps his pony and horse to collect some horse manure as fertiliser for our allotment yesterday. Apparently the horse manure is cleared out together with the horse bedding everyday. My colleague is currently changing the bedding twice everyday! Because his horse has strained one of her muscles or tendons. Really high maintenance to keep a horse is it not? Which in a way makes me a little more committed to do well on the allotment. As surely I can afford to spare some time for the allotment as well?Fortunately the bedding my colleague use for his animals is made up of straws and hays. Because if sawdust or wood shavings are used instead, the manure and bedding mixture is not going to be suitable for use as fertiliser directly. Whilst the horse manure is good to use as fertiliser, the sawdust or wood shavings are not crop friendly. Apparently when wood breaks down in the soil a nitrogen deficiency occurs, which stunts the growth of crops. There are ways to combat this, like adding nitrogen fertiliser. But we obviously are not interested in such extra activities :)Bags of “black gold” that look almost like soil were dug from the bottom of the manure and hay “mountain” yesterday. Very satisfied. Will work on the allotment in anger from next week once we get our car this coming Tuesday!

The importance of servicing a bicycle

I must have been cycling for 5 years now, on the same bike I bought through the Cycle-2-Work scheme. I have mended punctures numerous times, changed brake pads at least once for both wheels, and replaced freewheel and chain a year and a half ago. But not once have I really serviced my bike. In fact I have not even cleaned my bike before! I mean I have put on the odd lubricants on my chain every now and then, and tightening the brake cables when absolutely need to. But I really haven’t found the need to bring my bike in to a bike shop to get it serviced, until my brake cable got so dodgy that I can hardly brake my rear wheel.Cycled to Halfords about a week ago, looking to buy a fixed lock that I can mount onto external wall to secure W’s bike. Then found out that I can still purchase their one-year bike plan, which includes bike servicing, because my bike was bought from Halford. In fact the bike mechanic can still recall that I bought the bike there! I found this rather unbelievable, but anyway he had a look at my bike to confirm and thought my bike was still in, well, tolerable condition. Fantastic! Because I was toying with the idea of bringing my bike to a local bike shop in Reading town centre instead, as it is easier for me to leave and collect. But at only £18 for a one-year bike plan, it was an easy decision.Collected my bike today. And I honestly could not remember that I can cycle so quickly with my bike! I know my bike has now been pumped up, more than I usually am accustomed to. But it is still incredibly quick. Gear changes are much smoother, and I don’t miss certain gears anymore. The brakes are very responsive as well. Had I known that maintaining my bike in good conditions can make such big differences I would have sent my bike in to the bike shop more frequently, perhaps once a year. Wasted too much energy cycling for too long!