Midgets standing on the toes of others

Happy coding

AngularJS - Delay Controller Initialization for Asynchronous Operations

In an AngularJS web application, a controller requires some data for initialization, but this data needs to be retrieved from server. One solution is that after controller is initialized, use $http service to get the data and returns a deferred. But this will change the usage of data to asynchronous operation, which may not be possible for all the operations. People usually prefer to synchronous operations. Another solution is to delay initialization of controller until data is retrieved from server successfully.

To do this, we need to use a run service to start retrieval of the data.

Jekyll - Bootstrap Navbar Active Status for Different Pages

When using Jekyll to create websites, Twitter Bootstrap is a very good choice for styling. Typically there will be a layout template for all the pages. When using Bootstrap’s navbar, the basic markup of the navbar is put into the template, each page’s content is put into separate markdown files. Then we need to add active class to the correct <li> element in the template to make sure that in each page only the corresponding <li> element has the active class.

To solve this issue, I created a small Jekyll plugin to correctly generate the class name for navbar.

CoffeeScript Notes and Tips

CoffeeScript is a popular language used by many frontend developers, I collected some useful notes and tips.

Find first/last element in array

CoffeeScript’s destructuring assignment can be used to easily get array’s first and last element.

[first, ..., last] = 'a,b,c'.split(',')
[first, ...] = 'a,b,c'.split(',')
[..., last] = 'a,b,c'.split(',')

Gridlines for Google Maps

View GitHub repo

This is a small JavaScript file to create latitude/longitude gridlines over Google Maps.

The original version was made by Bill Chadwick and then other contributors continued to improve it. Refer to the file’s comment for more information.

I made some improvements and made this library available in Bower.

  • Fix JSHint errors.
  • Fix the issue that this library causes map to freeze in Chrome/Safari on Mac.

OAuth Signature Base String Decoder

When I was debugging an application used Xero’s API, I found out it’s hard to see the request content once some errors happened. The only thing I can get is the signature base string. But this string is encoded, so I need to decode it first. Then I wrote this small web page to do the decoding.

To use it, see this page.

To see the source code, go to GitHub.

Magmi Indexing Issue With MAMP

When using Magmi to import products into Magento, you may use Magmi Magento Reindexer plugin to re-index, but you may encounter following error if Magento is run by MAMP.

SQLSTATE[HY000] [2002] No such file or directory

To solve this issue, use following command

sudo mkdir /var/mysql
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

Use Web Service to Get Magento Categories

Magento’s web service can be used to retrieve data from Magento. Magento support SOAP/XML-RPC and REST service. SOAP/XML-RPC web service is discussed in this example.

Before using the web service, make sure a user and its role is created in Magento. Username and API key is used for authentication. The user’s role should have the required permission to access certain resources.

Some Linux Management Tips

During daily operations, I found following tips may be useful.

DNS resolve error in Amazon EC2

I found a Amazon EC2 instance cannot resolve DNS names. It turned out that the /etc/resolv.conf file is empty. Modify the file to look like below

domain us-west-2.compute.internal
search us-west-2.compute.internal

The configuration may be different. You can copy it from other EC2 instances.






在招聘时,这边的公司比较重视之前的项目经历和其他人的推荐。一般都会要求打电话给原来的单位做reference check。所以一份好的CV是很重要的。招聘的职位方面可以从Seek或LinkedIn等招聘网站上找到。