How to implement achievement system in CodeIgniter

In this post, I'm going to implement a reward system using PHP, similar to the current console generation's game achievements. Certain user interactions which satisfy the game's predefined set of requirements will trigger an event of showing the reward. E.g. Survive a fall from 400m will unlock the achievement of "Die Hard".

How to implement this feature in PHP? Since I've been working on CodeIgniter MVC, I shall introduce you a library, simply called as "CodeIgniter Events" by Eric Barnes and Dan Horrigan.

Steps

  1. Download the latest CodeIgniter here, version 2.1.3 as of writing 
  2. Download CodeIgniter Events library here
  3. Add the autoload line in config/autoload.php and put the events.php in application/libraries folder

Tasks

Whenever user types more than 5 characters into a text field and clicks 'Send' button, it will trigger the event class and show the achievement text.

Solution



My toilet's flushing system is hissing...

Bills do like to come around end of the month, don't they?  I got a shock the other day when my water bill arrived, it's $100 more than the average.  I checked the bill details and found out the sewage charge is way more than usage.

Let me guess, this could be due to
  • People in the house is peeing and shitting more often
  • The sewage meter is malfunctioned
  • Somewhere is leaking!!

I called a local plumber (which I found his contact from TrueLocal) and got the second shock.  They're going to charge $60 on arrival to the property (even though they're based in a neighbouring suburb), $20 for every 20 minutes.  It would take them at least 1 - 2 hours to carry out leak investigation and fixing.

Looking at my dry wallet, I decided to fix it on my own, the most suspicious thing would be the hissing sound coming out from the toilet's flushing system.  The hissing noise will stop if I twist the screw a bit tighter.  But when water refills the tank, the noise starts again.  Googling the issue leads me to exchange of a flapper in the outlet valve of the flushing system.

Steps to do to confirm a leak:
  1. When the water tank is filled, turn off the water supply where the minitap is normally situated below the flushing system.
  2. Come back after 15 - 30 minutes, check if the water level has dropped.

In my case, the water tank has gone empty.  Right, leaking issue half solved!  In order to let the professionals to identify the exact problem, I disassembled the outlet valve and brought it to Bunnings.  Have the wrong size of flapper substituted (it's still leaking!), I then drove to Caroma service centre and bought another flapper (price is < $2.00).  Once it's fitted into the outlet valve properly, all fixed!

TIL
  • water company charges any amount of water coming in and going out of the property 
  • not all flappers can fix a leaking valve, even though they look very similar.

Step-by-Step Guide

Turn off the water supply
Take out the middle (yellowish) outlet valve, the right  cylinder is the inlet valve
The outlet valve structure, flapper is shown as the black rubber plate at the end to prevent water from flowing into the toilet bowl
Replace it, the old one may look bigger as it has inflated along the years.  The new flapper as seen in the packaging is the wrong one that I've bought from Bunnings
Remember to slightly turn the platform that holds the flapper clockwise until they're firnly attached.  Install it back, mission accomplished!!

How to use POCO C++ library to receive emails and analyse contents

I've one task to do, and that is:
  • Get emails from accounts, account info (username, password, saveBody, saveAttachments) can be obtained from EmailInboundConfig object
  • Retrieve subject, each attachment's filename

After comparing 3 open source C++ email handling libraries, I've decided to give POCO library a go.  Remember to include the following in the header (*.h) files.

#include "Poco/Net/POP3ClientSession.h"
#include "Poco/Net/MailMessage.h"
#include "Poco/Net/PartHandler.h"
#include "Poco/Net/MessageHeader.h"
#include "Poco/Net/NameValueCollection.h"
#include "Poco/Net/QuotedPrintableDecoder.h"
#include "Poco/Net/MultipartReader.h"
#include "Poco/Exception.h"
#include "Poco/StreamCopier.h"
#include "Poco/Base64Decoder.h"
#include <iostream>
#include <fstream>


How to convert hard disk format from NTFS to Fat32

Another weekend, another task to do to make life easier. This time I will work on upgrading my 2008 phat Playstation3's 40GB hard disk to a massive 320GB. Since I play games a lot and games nowadays require larger space of game data for faster processing, I find myself having to remove previous games' install data just to accommodate enough space for the new ones. This is definitely a daunting task, in malay, we simply call it "potong stim".
‘Potong Stim’ literally means cutting steam. It is a term used for someone who kills the enthusiasm of others.
TL;DR Ruin the good mood!!

Tools required:
  • Screwdriver with cross heads aka Phillips-head
  • 2 portable USB powered hard disk: One for backing up the PS3 (> 80GB) and another one for PS3 firmware (~ 200MB)
  • 1 new 2.5 inch portable hard disk: Western Digital Scorpio Black 320GB 7200rpm 16MB SATA2 (Model No.WD3200BEKT) $71.50
There're plenty of online step-by-step guide on how to backup data, switch hard disk and restore data from backup, you can refer to "Related" section below. What I would like to write about is the 2 problems that I encountered which are not covered by those articles.


Q: How to format the new hard disk from NTFS (default) to FAT32?

Believe me, I've spent hours and gone through all the hard part for you. Below is the pseudocode:

IF (you're using Windows 95/NT/98/Me/2000/XP) {
    CompuApps SwissKnife V3 is the best option. 
    Download it here. 4.35MB 
} ELSE IF (you're using Windows 2000/XP/Vista/7) {
    SwissKnife won't work at all in Win7. Try Tokiwa's FAT32Formatter.  
    Download it here. 184KB
} ELSE IF (your thumbdrive capacity < 32GB && Use Diskpart feature in command prompt) {
    [01] Plug in your USB Flash Drive 
    [02] Open a command prompt as administrator (Right click on Start > All Programs > Accessories > Command Prompt and select run as administrator) 
    [03] diskpart 
    [04] list disk 
    [05] select disk 2 //Assume 2 is your USB drive 
    [06] clean 
    [07] create partition primary 
    [08] select partition 1 
    [09] active 
    [10] format fs=fat32 //Append "quick" option for quick format 
    [11] Assign 
    [12] Exit 
    reference
} ELSE {
    Give it one last try, 
    [01] Right click on drive in "My Computer" 
    [02] Choose "Format" 
    [03] Choose "FAT32" //NOTE: exFAT is different from FAT32 
    [04] Check "Quick Format" option 
    [05] Click "Start" button

    God Bless You 
}

I use Tokiwa's FAT32Formatter, this incredibly lightweight software did its job in less than 10 seconds for converting an empty 150GB drive from NTFS to FAT32. Impressed? Hell YES!


Q: Why PS3 can't find the .PUB (firmware) in the thumb drive?

I downloaded PS3 firmware (4.25 as of today) from AU Playstation site and transferred the xxx.PUB to another portable thumbdrive. But pressing 'Start' and 'Select' buttons simultaneously (as said in the on-screen instruction for restoring data) cannot detect the firmware update file in the drive.
SOLUTION: You need to create this directory path in the thumbdrive: PS3/UPDATE/xxx.PUB

Other

  • Time spent to backup a 38GB data is approximately 2 hours, same applies to restore the data to the new drive.
  • DLCs are included in backup as well. But it needs to be "activated" again somehow. E.g. Borderlands cannot detect any of the installed DLCs until I downloaded and reinstalled one of the DLCs from PSN.
  • Windows do have the limit of formatting drive (>32GB) to FAT32 no matter what version of the Windows OS. 

Related:

Job Interviews

Not going to lie, I've been going to interviews lately to see how things have changed along the years and of course, look for better opportunities.  It's either phone interviews with a job agents or face-to-face interviews in potential employers' offices.

2004
- Preferred languages: VB.Net

2008
- Preferred language: Cobol

2012
- Preferred language: HTML5, Ruby on Rails, Mobile (J2EE, Android)
- Requirement: Agile

Below is my checklist before going for interviews:
☑ Resume is modified to focus more on tasks and achievements
☑ Iron your shirt and trousers, wear a business tie and clean shoes, have a clean face
☑ Do research on the company or interviewer by checking out the official website or social networking sites, e.g. Linkedln, Twitter, blog
☑ Do revision on behavioural and technical questions that will be asked
☑ Be cool or at least look comfortable
☑ Have a good breakfast

Is there anything else I've missed out? If not, how the hell do I fail so much, I've been wondering. This article does point out something crucial.
Most interviewers fall prey to unconscious biases and focus too heavily on experience rather than competence.

As a mid-level programmer who works on various programming languages (Java, Ruby on Rails, PHP) along these years, I strongly feel that I can contribute more as my skills are not fully utilised yet. But the flawed filtering process by most employers categorized me as low end programmer. On the contrary, all my ex-employers are happy to have me around in their department during my employment. My proactiveness and strong adaptability at work cannot be seen in the 20 minutes or so interview. 

Ridiculously, I just can't score high in technical questions which aim to stress you up because most solutions can be found online. Of course one can code everything from scratch if you're a super coder, but what's the benefit of having a might-be buggy solution compare to modifying an existing code snippet from StackOverflow.

One thing that annoyed me the most would be asking "Do you have any experience in Agile development?". Let's have a read on its definition on Wiki,
Agile software development is a group of software development methods based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. It promotes adaptive planning, evolutionary development and delivery, a time-boxed iterative approach, and encourages rapid and flexible response to change. It is a conceptual framework that promotes foreseen interactions throughout the development cycle.

May I know how hard it is to adapt to a new methodology in software development? Is it harder than paying the ever increasing utility bills or getting a payrise from a tight-ass stingy company?

In conclusion, I know that I'm definitely
NOT suitable if a company is looking for:
- a gun programmer who eats, lives, breaths and shits around programming
- a scholar who memorises all the programming jargon

TOTALLY suitable if a company is looking for:
- a proactive, organized programmer/analyst who requires minimum supervision
- get things done in a clean and efficient way, will work ass off to meet deadline (normally don't happen though)
- produce documented codes and communicates well in a team
- propose multiple solutions and welcome discussions to pick the best

Just curious, is there anyone out there who has similar situation as me? Maybe I should just switch my profession, get the hell away from programming. Heck, I don't know, mind blown!


Related: