Category: Tech, Code & AI

  • Buying is easy

    But letting go is not.

    I spent several weekends in August tidying up old PCs and other computer hardware, hopeful that it would benefit some people.

    One laptop went to a needy family. That was easy, because it’s a small laptop (a Netbook, to be exact.)

    There were two other needy families who wanted computers, but never came. The pile of old computers remained uncollected in my parent’s office for over two months.

    The dateline I gave was 31st October, so mid November we loaded all of them to the back of the car and drove them to the Salvation Army only to be rejected because “Windows XP is too old.”

    These are perfectly working computers that I cleaned up, re-installed the OS, packed neatly and labelled the hardware specifications.

    I felt a little discouraged, so I tried advertising them again on Facebook. This time, 3 more pieces of hardware reserved, pending collection.

    I still have 2 computers and a bunch of old monitors, keyboards and network switches.

    Drove to Funan Center and dropped monitors, keyboards and network equipment off at the information counter where they provide e-waste recycling.

    Old hardware at Funan lift lobby
    Above: Old hardware at the lift lobby at Funan Center

    I drove the last 2 computers to office where I intend to keep them for a bit more, or perhaps place notices on the lift doors to see if anybody wants them.

    Just as I was unloading the computers from my car, a foreign worker who cleans the trash at the office building saw me placing the computers on a trolley. His eyes lit up as he approched me.

    “This. Throw?” he asked, pointing at the computers.

    “Ya. If you want, take them — all working,” I said.

    “Working?”

    “Ya.”

    He pushed the trolley to the back of the refuse area where I saw some old furnitures and a HUGE server (something like a massive IBM blade chassis). He unloaded my computers, then returned my trolley.

    I hope he’ll find good use for them.

    I’m still puzzled why Salvation Army would reject these perfectly working computers. I know they try to sell them for money as it is logistically not worthwhile to transport them to third world countries, but they could have given them out for free at the thrift store too. Maybe they have insufficient manpower; I feel for them because I get upset every time I see the pile of junk people leave behind at the outdoor donation bins.

    Salvation Army is not a recycling facility.

    Nevertheless, a good lesson learnt here is that things are easy to buy, and never easy to let go. I’m trying to be a minimalist because I value my personal space more than anything else. Space is expensive and precious, especially on this tiny island.

    Think before you buy.

    P.S. People asked why I never offered to deliver the computers to the needy families since I drive. I don’t believe in giving to laziness. I worked my ass as a student carrying computers and computer parts on the bus to and fro my home and Sim Lim Square as a kid, and I don’t believe they can’t drop by and pick up a CPU on a bus. I will give for free, but at the very least they will have to come get it.

  • Buying Mobile Phones in Singapore

    There’s been a piece of news recently where a Vietnamese tourist who made only $200/month had to kneel down to beg on his knees to get a refund of his money for an iPhone 6.

    I think a lot of people still do not understand the ins-and-outs of this trade. Being a victim of similar scams at mobile phone stores in the old days, I subsequently started a business of my own to prove that it is possible to make an honest living.

    There are few very common tricks that people fall into. The simple ones are these: –

    • Adding taxes to list price after the deal is made. Such sellers usually add an additional 7% GST to the listed price, but sometimes the seller is not a GST-registered business.
    • Missing parts, such as charger and earpiece, requiring a top up. This is the scam I fell for.
    • Not getting the device you wanted, i.e. a fake, or a used item instead of a new one.

    The more complex scams is seen in the news above, where a hidden contractual clause would require you to purchase additional items. There’s also another type of scam known as the swap-bait, where you would purchase a device, then test it and realise it is faulty, but have no choice but to pay extra for an upgrade because the faulty item was the “last piece”.

    How to avoid being scammed?

    Be sure to ask for nett pricing, i.e. tax inclusive price. Be sure to ask if all the items are included in the box, such as charger and earpiece. Also be sure to check the lifetime call timer on the item to ensure that it is 100% brand new (if you are buying a new device). Test the device before making payment. Finally, read any agreement carefully before you sign.

    Sometimes the products may not be sealed, and that is OK because it is common for mobile phone stores to buy from a consumer who has re-contracted with a telco (this is called “buy-back”), then resell it. These devices are still considered “brand new in box” (BNIB), but may have a lapsed warranty of several days. This is how these stores are able to offer good prices well below the recommended retail price (RRP).

    The Vietnamese tourist was unfortunate. These are definitely not normal business practices in Singapore. There are many stores around that make an honest living, and I suggest that people do their own research and go to stores that publish open pricing and have a large social following. The top two such independent stores in Singapore are WhyMobile and Mobile Square.

  • Why status fields must die

    I’m sure we have seen this happen: A programmer forgets to add a status = 1 condition/check to an SQL query and the app disintegrates.

    Status fields can be useful in some ways especially if the range of values are large, e.g. to track order status. But the most common use I’ve seen is data retention, i.e. keeping a deleted record. The status field is an ancient way of archiving a record, and this design exists in almost every application I’ve seen, because back in those days schools told us to normalize tables. Some companies even make it a mandatory design requirement to have this field in every table — even in many-to-many join tables.

    We should avoid designing tables with record deletion status fields. Why? There’s many reasons why, and the common accidental omission of the status check is one of those reasons. There are also different data types being used, sometimes highly inefficient for indexing — for example INT, a 32-bit signed integer is very commonly used for storing values 0 and 1. The ambiguity is also a common problem: What does 0, 1 and 2 stand for? Where are these defined? In constants, or cross-referenced to another table? The status check is also an additional condition that the database needs index/filter. What’s worse is that sometimes the check is done at the model layer, while other times the check is done at the controller layer… or maybe both… or maybe none.

    So what’s a better way of dealing with record archival? If there’s really no reason to keep the record, delete it.

    If the record should be kept for some reason, archive it into another table, a technique known as partitioning. It would also be more efficient to search a table containing only records you need to query.

    Partitioning also allows you to tier by storage performance, e.g. place “live” tables on high performance storage, and “archive” tables on slower storage devices. You can also tweak indexing to cater to different search patterns on both sets of data.

    Archiving data is very easy, and is not much more complicated than a delete: If the two tables are identical (in column definition), simply use INSERT INTO … SELECT, then DELETE.

    If you are worried about deletes being I/O intensive, then consider batching the deletes or having a cache. This will depend on how your application is designed.

    (Side note: MySQL 5.1 has a new partition feature that can be used to automagically partition tables, but that is more for performance purposes. This article is discussing a design issue to remove common errors in programming.)

    Edit: Updated Oct 19. Friend asked about status fields that may have a large range of values, such as transaction statuses. These are OK to remain as fields. I was primarily targeting record archival.

  • The truth about power banks

    The truth about power banks

    Ever wondered why your 4,000mAh may not even charge your 1,570mAh iPhone 5S twice? Here’s why: –

    Devices consume power (“P”) and that is measured in watts. To derive watts, we need to multiply the amperage (“I”) by voltage (“V”).

    P = I x V

    * Also note: 1A = 1,000mA

    The 4,000mAh rating of the power bank refers to the charge capacity of Lithium-ion cells in the power bank, and that is different from what comes out of the USB port because both operate at different voltages.

    Lithium-ion batteries operate between 3.2-4.2V (stable at 3.7V) while USB devices operate at 5V.

    This means that: –

    • The power bank can only deliver 4Ah x 3.7V = 14.8Wh
    • It will only charge a 5V USB device to 14.8Wh / 5V = 2.96Ah or 2,960Ah

    Now, you must be thinking: “Hey, my phone also uses a lithium-ion cell, so it should convert (back) to the same”.

    It is partially correct to assume that, but power reduction process will likely result in losses (usually in the form of heat) so it is not a 100% efficient process.

    The power bank itself would also be stepping down (or stepping up, depending on  design) its voltage. If it’s cells are wired in 2 series, it would need to step down from 3.7V x 2 = 7.4V to the USB output voltage of 5V before you can use it to charge your phone.

    With two devices stepping down power (Power bank > USB > Phone > Phone Battery) the efficiency can be as low as 64% (80% x 80%).

    So as an example, to charge a 1,570mAh battery in the iPhone 5S, we will need a constant 1.57A x 4.2V (charging voltage of li-ion) = 6.594 watts.

    Assuming both the power bank and phone are only 80% efficient at converting the power, this would mean that the power bank must deliver at least:

    6.594W x 1/(0.8 x 0.8) = 10.3W

    10.3W / 3.7V = 2,784mAh power bank is required to charge an iPhone 5S

    Also remember that while charging your phone, the phone is likely to consume some power during the process even if it is completely powered off because it has to regulate the charging process, alternating between charging and measuring the charge state of the battery. This is required to protect the battery in your phone from over-charging.

    Another thing to know about is charge rate (“C”). The higher the charge rate, the faster it charges. At 1C, a battery will be fully charged in an hour. At 2C, it will be charged in half an hour.

    Most phones are designed to charge between 0.5C to 1C to ensure maximum lifespan of the battery. This means it will take between 1 to 2 hours to charge. Charging lithium-ion batteries above 1C may shorten its lifespan (and that’s why you should not use cheap docking chargers or avoid “quick” chargers.)

    Why should you care since the phone is already regulating the charge rate for you? That’s because the charge rate affects the current draw on the power bank.

    If a 4,000mAh power bank claims to provide a 1A USB charging port, it means it should deliver 1A x 5V = 10W of power constantly.

    To charge an iPhone 5S @ 1C would require at least 1.57A x 4.2V = 6.59W (before efficiency losses). If we factor in efficiency losses @ 80% for both the power bank and the phone then 6.59W / (0.8 x 0.8) = 10.3W. That’s approximately 1A!

    For a bigger device like a Samsung Note 3 with a 3,200mAh battery, it is likely to be charged at 0.5C. Quick calculation yields (3.2A x 4.2V x 0.5C) / (0.8 x 0.8) = 10.5W which is also just above 1A.

    As you can see most devices require around 1A to charge, but if you are going to be using your phone while charging then the current draw may well exceed 1A and you will need a power bank capable of delivering more. If you use an underrated power bank you may damage (overheat) its internal voltage regulators.

    Lastly, if you are charging your phone, try not to use it at the same time as doing so might also put too much current through the phone’s voltage regulator causing it to fail prematurely. This is especially common on bigger phones. If you feel your phone getting hot, it’s a sign to stop. Depending on phone design, you may have to change the entire logic board.

  • What to do with old computers

    What to do with old computers

    The staffs in the office got new laptops last year (thanks to the government’s PIC grant) but the stockpile of old hardware became an eyesore. What should I do with them?

    I found out that one of my friend’s a volunteer worker and needed computers for needy families, so I decided to spend my NDP weekend sorting out them out. I thought it was going to be an easy job, but turned out it burned my entire weekend.

    Me and my wife started late Saturday afternoon and missed the National Day Parade. We worked till 12:30am and decided to continue again on Sunday (today), and it’s still not yet done. There’s still two more computers in the queue.

    donation1
    Piecing together parts from an old “beige box” 2U server and desktop to make a working computer.

    The problem was that the computers left sitting started to degrade — CD/DVD drives, hard drives, motherboards, graphic cards all started to fail. So the tip here is that if you have a computer you do not want any more, wipe it ASAP and donate. Some of these computers are over 10 years old (Pentium 3!), so it was amazing to see them still working.

    The inside of a 14 year old HP desktop (manufactured in 2000). Not a speck of rust.
    The inside of a 14 year old HP desktop (manufactured in 2000). Not a speck of rust.

    I was also impressed by how well the old HP desktops held up after 14 years. These thick, sturdy steel cases must have been galvanized because there’s not a single speck of rust on them. Machines (including servers) these days are no longer made to such high standards and feel flimsy.

    There were also old networking equipment up for grabs, but I could not see how a needy family would need a 24-port switch, so I found another friend who might have a use for it by sending it to schools in Cambodia.

    Old 3Com Superstack switches, hopefully to be donated to schools in Cambodia.
    Old 3Com Superstack switches, hopefully to be donated to schools in Cambodia.

    The last problem I need to solve would be to get working software into these machines. Some of the PCs had OEM Windows XP (luckily we kept all the original CDs).

    Update: The list of hardware to be donated have been distributed and they have been collected, albeit slowly. But it definitely feels good to know that it is going to somebody who needs it, rather than a karang-guni man who will probably just scrap it for parts.

  • Building another Joomla or WordPress site?

    Looking to build a website for your business? You have been warned.

    Somebody I know had her company’s site done by one of those companies selling Joomla or WordPress ‘packages’. When she saw the end result, she face-palmed. When I saw it, my reaction was pretty much the same. The site was riddled with horrid mix of serif and sans-serif font, bad alignment, varying font sizes, etc.

    For about $2,000-$3,000 dollars you can have these people build you a Joomla or WordPress site, but you really pay only about $800 for it because the government is helping you pay the other 60%, or about $1,200 via the Productivity and Innovation Credit (PIC).

    No, this is not a blog entry to advertise the PIC. There’s rampant abuse of the PIC scheme, and it has actually created a lot of crappy work (and IMHO, crappy jobs). Not to mention photocopiers selling for $15,000 with “cashback”.

    A lot of these web “design” companies are selling you nothing but pre-built templates reused over and over again. No surprise all their client’s websites look pretty much the same. With some changes to color and images, bingo! They’ve transformed the template into your website.

    But wait… it still looks like crap. Why?

    A lot of ‘designers’ are really just ‘developers’. Designers come from art school. Developers come from IT school. A lot of these designer-developers don’t even understand basic typography, let alone color theory, or help you with illustration or photography. And if they aren’t good in English, expect your site to be riddled with grammatical and spelling errors.

    When you engage a proper web design firm you actually are paying for a lot of things. A good company will actually advise you on the kind of content or site structure you should have, and also be able to provide additional services like copywriting, photography, illustration, etc. A proper design firm needs to hire both designers and developers, and they’ll also need somebody to manage these two very different groups of people and ensure they don’t kill each other.

    If you are really looking for a cheap solution you can actually buy beautiful templates off sites like Template Monster for a fraction of the money, then engage a freelancer to help you add content and deploy it to a hosting provider.

    You’ll want to choose a template with the similar color theme and typography as your corporate brand. You don’t want to mess with colors or fonts — that’s a job for designers.

    Nowadays the first impression people have of your company is through your website. Don’t underestimate the impact a website might have on your business. Messing a website up is as good as messing with the signboard and interior design of a retail shop.

    One final word of advise — make sure you get a company that can support you through upgrades and security patches of the CMS you use (WordPress, Joomla, Drupal, etc.) preferably one that provides hosting service as part of the package. Most people with Joomla sites built a few years back would have had their site ‘hacked’ by now due to security issues (I’ve dealt with a lot of these cases). If you must, choose WordPress. It’s better than Joomla in terms of security.

    It’s really 一分钱一分货.