Enable HTTP authentication on certain domain Sep 18, 2014

Basic HTTP authentication is one simple way to limit public access to your website prior to launch.

The first thing you need is .htaccess file which contains all the configurations. The second one is .htpasswd containing username and password. You can use this website to generate .htpasswd file for you http://www.htaccesstools.com/htpasswd-generator/

In the sample below, I am trying to enable HTTP authentication only on certain domain. On the first line, I set enviroment variable if the domain name is equal to “www.bundabergfestival.com.au”. On line 7, I tell .htaccess file to deny any access by using the live_uri variable. I hope that explanation is pretty straight forward.

... ➦
AngularJS Free Course by Code School May 26, 2014

I spent some time last weekend to run through the new AngularJS course by Code School. This course is sponsored by Google which means you don’t need to pay for the Code School membership to play this course. AngularJS is one of the popular Javascript frameworks to build single page app application. You might be familiar with other frameworks such as Ember.js, Backbone.js and Knockout.js.

I really enjoyed the course and definitely learned something new from it. It covers the basic concept about directives, services and dependecy injection. I didn’t understand those features when the first time I learned about AngularJS. In the beginning of learning AngularJS, I tended to copy and paste code without understanding the meaning behind it. This caused confusion when I tried to learn more about the framework.

... ➦
Configuring Elastic Beanstalk Environment with .ebextensions May 22, 2014

At Captiv8, we are using Amazon AWS to host most of our PHP projects. We are heavily rely on Elastic Beanstalk to help us set up PHP environment, database and load balancer. On top of that, we are also managing our own server image based on Amazon AMI. In this image, we installed additional software and packages that we need for our application. However, this approach has a drawback as it is difficult to maintain the image and track changes. Everytime you need to update the image, you have to create new server, install the new software and export it into new image. This will leave you with bunch of different images and it is hard to tell what are the things that have changed inside each image.

... ➦
Audio Books Mar 27, 2014

Around October 2013, I decided to move from city to Gladesville which located 9 kilometres north-west of Sydney CBD. It wasn’t easy decision because I need to spend about 2 hours on commuting every day.

For the first couple months, I was fine with the long commuting time. I can distract myself with my phone or sleeping on the bus. However, I started to feel unproductive and I can feel it affected my concentration throughout the day. So, I tried to do some research on the Internet about productive use of commuting time. Most of the articles that I found suggesting to listen either podcasts or audio books.

... ➦
Add 'current' class to website menu in Rails Jan 15, 2014

It is common to have ‘active’ state or ‘current’ state on website navigation. This will help visitors to know which page they have selected.

This solution is based on Stackoverflow’s question which I couldn’t find. First, I’ll create a method inside Rails application_helper.rb file. I’ll call this method cp(). Here are the syntax:

1
2
3
4
5
6
module ApplicationHelper
  def cp(path)
    current_route = Rails.application.routes.recognize_path(path)
    "current" if current_page?(path) or params[:controller] == current_route[:controller]
  end
end

The method uses current_page and Rails.application.routes.recognize_path to get information about current page.

... ➦
Install the latest tmux on Ubuntu 12.04 Dec 06, 2013

In this post, I will show you how to install the latest tmux on Ubuntu 12.04. First, we need to install ‘add-apt-repository’ command on our machine. This can be done by running these commands:

1
2
3
sudo apt-get install software-properties-common

sudo apt-get install python-software-properties

After that you can add third party repository ( Ubuntu official repository does not have latest tmux at the moment )

... ➦
Rails 4 CORS Oct 29, 2013

McFlyyy pointed out another solution to solve this problem. I haven’t tested it myself so follow it at your own risk Click Here

I was trying to use Rails to build REST API for my AngularJS app and came across CORS error on my Chrome developer tools.

According to Alexey Vasiliev, Cross-origin resource sharing (CORS) is a web browser technology specification which defines ways for a web server to allow its resources to be accessed by a web page from a different domain. Such access would otherwise be forbidden by the same origin policy. CORS defines a way in which the browser and the server can interact to determine whether or not to allow the cross-origin request. It is a compromise that allows greater flexibility, but is more secure than simply allowing all such requests. CORS is supported in the following browsers:

... ➦
Fix npm symlink problem in Vagrant Oct 24, 2013

Today I encountered weird symlink error when trying to install npm modules on my Vagrant Ubuntu Box. The error says “pm ERR! Error: UNKNOWN, symlink ‘../which/bin/which’”.

After quick Google, it turns out the problem is caused by npm trying to create symlink which is not supported on Windows ( I am using Windows 8 as my host machine ).

Here is quick solution which allow you to install npm modules without creating any symlinks :

... ➦
Trailing Characters ^M Sep 18, 2013

This morning I ran into weird errors in one of my Vagrant machine. These errors come up when I was trying to run tmux and vim:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Error detected while processing /home/vagrant/.vimrc:
line    1:
E488: Trailing characters: nocompatible^M
line    2:
E488: Trailing characters: nu^M
line    3:
E488: Trailing characters: nobackup^M
line    4:
E488: Trailing characters: nowritebackup^M
line    5:
E488: Trailing characters: noswapfile^M
line    6:
E488: Trailing characters: hlsearch^M
line    7:
E488: Trailing characters: ruler^M
line    8:
E474: Invalid argument: laststatus=2^M
line    9:
E474: Invalid argument: tabstop=2^M
line   10:
E474: Invalid argument: shiftwidth=2^M
line   11:
E488: Trailing characters: expandtab^M
Vim: Error reading input, exiting...ne down, b/u/k: up, q: quit
Vim: Finished.
Press ENTER or type command to continueVim: Error reading input, exiting...
Vim: Finished.

I had similar problem before when trying to edit file from Windows machine inside vim. ^M character is added by Windows machine to mark newline in their files.

... ➦
Zeus inside Vagrant Sep 13, 2013

I have been using Vagrant as my development environment for the last couple weeks. It has been very helpful as I prefer to use Linux as my development environment and I can only use Windows at my workplace. With Vagrant, I can easily set up new Linux machine, install Vim plus all the plugins and completely separate development machine for each project.

Today, I was trying to use Zeus to speed up my Rspec test inside one of the Rails projects. I found this gem through a screencast by Ryan Bates about Fast Test.

... ➦