Alvin Poh

Author: Alvin Poh (page 2 of 48)

How to redirect one domain to other domain with all query string variables (htaccess)

If you ever have the need to move domain names, the following .htaccess code will help move all visitors to your second domain name. This method also preserves your URLs’ query string variables, so there’s a less likely chance of something breaking.

You can use this:

RewriteEngine On
RewriteCond %{HTTP_HOST} firstdomain.com$
RewriteRule ^(.*)$ http://www.seconddomain.net/$1 [L,R=301]

How to find and replace a text string in all files on your cPanel / WHM / Linux / Unix server

If you need to quickly find and replace all occurrences of a string of text, the Linux shell is a very helpful too. To do this, we’ll be using the find, xargs, and sed commands. Find is pretty self-explanatory, and sed is short for “stream editor”, which allows you to filter and transform text. xargs is a command that takes in input and executes your chosen command on it – and in our following example, allows you to run the same command on each of the things the find command found.

Here is the command:

find /home/username/public_html/ -type f -name ‘*.php’ -maxdepth 4 -print0 | xargs -0 sed -i ‘s/ancientkg.pay/ancientsec.pay/’

In English, this means to find (find command) in /home/username/public_html/ any file (-type f) of file extension .php (-name ‘*.php’). It searches for 4 levels of sub-folders (-maxdepth 4) after your specified location, and edits files in place (-i). The arguments -print0 (for the find command) and -0 (for the xargs command) must be used together. What it does is separate file names with a 0 (NULL) byte so that file names containing spaces or newlines won’t cause errors.

To limit your search to only the current folder and not search through any sub-folders, use the -maxdepth 0 option.

How to find and replace text string in all MySQL tables

The following tutorial is helpful if you have a MySQL database and need to find and replace all occurrences of a string, for example, replacing “www.YourOldDomain.com” with “www.YourNewDomain.com”. This is useful if you are moving or cloning your website to another domain, especially if you are using software such as WordPress.

First, go to your old domain name and export the ENTIRE database, including enabling the option to “drop tables” if they’re already present. If you’re using PHPMyAdmin, you’ll want to select the option as highlighted below. To see these options, choose the Export Method: Custom – display all possible options.

how to find and replace text string in all mysql tables

Once you’ve obtained your .sql file, open it up in a text editor like Notepad, and do a find-and-replace of the string that you’re looking for.

After which, the next step is to import the .sql file back into your MySQL database. The “drop tables” command will remove all the existing tables, and then import your data. You now have a database with all the occurrences of your text string properly replaced.

How To Keep Indentation For The Second Line Onwards In Your Lists (CSS / HTML)

If you’re trying to preserve indentation for your lists, especially when you have multiple lines, then this is the code that you need. It’s fast, east, simple, and works to keep the indentation for the second line onwards (per bullet-point). As you’d imagine, this will work for both ordered (OL) and unordered (UL) lists.

li {
list-style-position: inside;
text-indent: -1em;
}

The Best Investment Strategy – The Lazy Portfolio

I’ve had many years of experience trading stocks and I’ve even dabbled into Contract For Differences (CFD) and forex. However, while I had my good times and great returns, I’ve also had my “investments” go belly-up or languish for months. If you’re young, “waiting for your investment to break even” may not seem like a bad idea, but if it’s $100,000 worth, and you have to wait a year for it to just breakeven, you’re not coming out of it flat – you’re also giving up the gains had you invested the money elsewhere during that one year. This is otherwise commonly known as “opportunity loss”. When you consider that you can put that same amount into a savings account that gets you 1% per annum, or a stock index exchange-traded fund (ETF) that might get you 8% per annum, you can start to feel the pinch.

Embarrassingly, it was only until recently that I found the concept of “lazy portfolios”. Essentially buying the whole market, it was the perfect answer to what I was looking for: a mix of diversification, lowered risks, indifference to bull and more importantly bear market cycles, returns that beat market benchmarks, and most importantly, takes no time and effort at all to implement and maintain.

Here are the 3 benefits of a lazy portfolio:

1. Saves Time

How do you know what stock will go up (or down)? You don’t. In fact, noone can. Not consistently, that is. So rather than to guess/gamble/speculate or spend hours of your time doing “research” and “analysis”, why not just buy the whole market? Stock index ETFs allow you to do so. When you consider that it is incredibly difficult to beat the market, why not buy the market, and enjoy the gains that the markets make?

2. No Stress

Worried about your portfolio’s performance? Not sure when the next bear/bull cycle will be? Concerned about when to buy or sell? Forget all of that. Use Dollar-Cost Averaging, or Value Averaging, or a combination of both. If you’re using the Lazy Portfolio strategy, you’d be more excited when there are bear cycles because you’d think of them as a great fire sale, and want to buy more then. Compare this to what people would normally do, which is to sell, and you can see how much more stress-less this strategy is.

3. Solid Returns

You might think that with all these benefits, a strategy like this would probably be low-returns as well, but you couldn’t be further from the truth: a lazy portfolio averages 7% annually. That’s the kind of returns that the stock market will average, and you don’t even have to pay much fees for this (we’re talking about something like 0.05% for a Vanguard ETF). Unlike mutual funds or unit trusts, you don’t pay fees of 1% to 5% a year. On an investment of $50,000, that difference will result in $97,866 after 30 years (with a 0.05% annual fee), versus $84,561 (with a 1.5% annual fee). And that’s assuming your unit trust beats the market (many fail to, even experienced fund managers).

Lazy Portfolio For A Singaporean

Interested? Well, as a Singaporean, we have the problems of a relatively illiquid stock exchange as compared to other markets such as the New York Stock Exchange, London Stock Exchange, or even the Hong Kong Stock Exchange. However, the Singapore Stock Exchange is getting better and more liquid with every year. Until then though, I have chosen to invest my funds elsewhere.

Case A: Investing in the US market

I considered the US markets, especially for their popular Vanguard ETF options. However, there is a 30% withholding tax on dividends of US-domiciled ETFs for international investors from a country without a tax treaty with the United States (Singapore is without a tax treaty). That adds up to a fair sum.

In addition to that, I didn’t want to risk any chance of dying and leaving my family the grand gift of a huge estate tax (this can be up to 55%, so don’t think that it’s a small amount). Since the lazy portfolio is a long-term approach, I didn’t want to park my funds in US-domiciled brokers and ETFs.

Here are some links for international investors:

IRS – Characterization of Income of Nonresident-Aliens

IRS – Some Nonresidents with U.S. Assets Must File Estate-Tax Returns

Unless you are a US citizen or live in a country with a tax treaty with the US, you should probably avoid holding US-domiciled ETFs. Read on for my solution to this.

Case B: Investing in the Canadian market

The next best market seemed to be the Toronto Stock Exchange, which has liquidity, and quite a range of ETFs. However, withholding tax was still 25%. That means for every $1 you get as dividends, you will be taxed $0.25. Ouch.

If you are feeling bullish about the CAD currency, and maybe plan on retiring to Canada, then this portfolio will make sense. The Global Couch Potato model portfolio that is recommended is made up of 3 equity ETFs, in equal parts.

  1. iShares MSCI EAFE IMI (XEF.TO, CAD): International equities ETF, covers the whole world except North American (Canada and USA)
  2. Vanguard US Total Market (VUN.TO, CAD): US equities ETF.
  3. Vanguard FTSE Canada All Cap (VCN.TO, CAD): Canada equities ETF.

The portfolio is no slouch, gaining over 10% every year for a 10-year period.

Case C: Investing in the London and Hong Kong markets

The best markets for Singaporeans seem to be the London and Hong Kong markets. Both London and Hong Kong have no capital gains tax. London-domiciled ETFs will have a 15% tax on dividends (at source – you don’t see this tax on your received dividends), and Hong Kong-domiciled ETFs have a 0% tax on dividends.

  1. ABF Pan Asia Bond Index (2821.HK, USD): The ABF Pan Asia Bond Index invests in domestic currency-denominated government and quasi-government bonds issued in eight EMEAP markets, namely, China, Hong Kong, Indonesia, Korea, Malaysia, Philippines, Singapore, and Thailand
  2. Vanguard FTSE All?World UCITS (VWRD.L, USD): International equities ETF, covers the whole world
  3. SPDR Straits Times Index (ES3.SI, SGD): Singapore-only equities ETF

How To Start a Lazy Portfolio As A Singaporean

I feel that my CPF acts somewhat as a bond component of my portfolio, so I’m reducing my bond component in my portolio.

The broker I use is Saxo Trading, which has a really straightforward account opening process. It has slightly more expensive trading commissions and rates than other brokers such as E*Trade, but has the benefit of not having any of the problems of US estate duties that I highlighted before. Saxo Trading does slap you with a hefty forex conversion fee (additional 0.5% on your conversion), so always try to fund your Saxo account in the currency that you want to trade with.

Request A Call From Saxo TradingHave someone from Saxo personally call you to explain and guide you with their accounts.






For me, since I wanted to buy ETFs denominated in SGD and USD, I simply opened a HSBC Multi-Currency Account, and denominated it in SGD and USD. This has a benefit over other local banks in Singapore because I could do a same-day transfer to Saxo Trading’s bank account, which is also a HSBC bank account. From then on, every transfer I make to/from my HSBC account and to/from my Saxo Trading account, could all be executed online and completed within the business day.

What’s Next – Maintaining Your Lazy Portfolio by Rebalancing

The only thing that you need to do is to make sure that your portfolio components maintain their ratios. For my portfolio, I’d just ensure that each equities component is roughly equivalent, and that my bond component doesn’t exceed half of my age (e.g. if I’m 30 years old, it should not exceed 15%). Since I don’t plan on selling, I merely add funds to the component that is lagging.

If, however, you plan on selling some components, then during your portfolio rebalancing (which can even be an annual affair – there’s no “right” time to do this), you would sell some units of your best-performing component, and add those funds to your worst-performing component and try to bring the mix back to their original levels again.

Enjoy!

And that’s it. After this, decide on a regular period in which to make more purchases of your ETFs, and leave your portfolio to do its work, and spend more time doing the things that you love!

How To Mass Update WordPress URLs After a Site Migration

If you’ve moved your WordPress installation from one URL structure to another, then you might find that certain things might break: for example, image paths.

Updating all your paths will just take a few seconds with a simple MySQL command. Go to PHPMyAdmin, a popular database management panel that your web host should provide you with, and open up your WordPress database. What we’re going to do is to perform an update of all BLOB fields, or in other words, update all the posts that you have at once.

Here’s the SQL command that you should run:

UPDATE `wp_posts` SET `post_content` = replace(post_content, 'oldurl.com/wordpress', 'newurl.com/wordpress')

Best Protein Bar Review: Which Is The Healthiest Of Them All?

I’ve been trying to change my diet to eat a lot cleaner and healthier food recently, and that means less of processed foods (hams, sausages, burger patties, candy, etc), sugared drinks, and artificial stuff, like artificial sweeteners. Unfortunately, that also leaves me in a bit of a problem when I get hungry in the middle of the day, or when I’m on the move, because I’m suddenly faced with a lot less options to turn to.

Protein Bars Are Convenient and Nutritious – But Which One Is Best?

I started researching on possible solutions, and I found protein bars: high in protein, convenient, and seemingly healthy. I started looking at the various kinds of protein bars available on the market, and got myself several brands. Unfortunately, I realised that not all of them were made equal. Even though they came with 20g or so of protein, some protein bars actually had the nutritional profile of a Mars bar!

I only found this out the hard way by trying at least 5 different brands of protein bars – Promax, Promax LS (Low Sugar), Pure Protein, CLIF Builder’s, Quest – before I started reading the nutritional labels closely, and finding out that some of them had WAY too much sugar.

Shocking Amounts of Sugars in Some Protein Bars

Take a look at these Promax bars for instance. I was wondering just how different the regular Promax protein bars and the Promax LS (lower sugar) protein bars are, until I looked at the nutritional label:

promax protein bar nutrition

These regular Promax bars have 30g of sugar! That’s almost half its weight! And yes – that’s almost what a Mars bar has in them too. After this fact dawned upon me, I realised that it was the reason why their wrappers were designed the way they were. If you noticed, the regular bars had no mention on the amount of sugars, just that it had 0g trans fat, and 18 vitamins and minerals. It was only the Promax LS bars that started to show off the fact that they had 9g of sugar.

promax protein bar compared

Best Protein Bar – Quest Protein Bar

The one protein bar that I found had a really good nutrition profile was from Quest. To me, this was the best protein bar around. It had only 1g of sugar, and didn’t have any artificial sweeteners too.

best protein bar quest

I found out that the flavor greatly changed how much I liked the bar’s taste though. Since taste is subjective, you might have to try the flavors out yourself. Personally, I liked these flavors the best: Chocolate Brownie was my definite favourite, followed by Cookies and Cream, and Cinnamon Roll, and then Double Chocolate Chunk. Here’s how the inside of Chocolate Brownie looks like:

best-protein-bar-quest-actual

Where to Buy Protein Bars

If you’re looking for the best place to buy protein bars, I highly recommend iHerb.com for their low prices, fresh inventory, and cheap world-wide shipping. I’m from Singapore, and iHerb.com ships to Singapore for free (or only S$4 for orders below $40). I use iHerb for all my supplements, and even things like soap, deodorant, salt, nuts, etc. Shipping takes only about a week, and is way cheaper than anything that you could get locally! Tip: Save $10 on your first order at iHerb with this iHerb coupon when checking out: VHW626

Olderposts Newerposts

Copyright © 2016 Alvin Poh

Web Hosting by VodienUp ↑