How to perforn basic authentication in AngularJS?

For this tutorial, I'll teach you how to perform a basic authentication with AngularJS. For the sake of example, we'll use github's API for basic authentication. If you browse that page now, you'll see a section for basic auth.

See that line with the curl command?
$ curl -u (username):(token)
That's what we're trying to replicate, but with the use of AngularJS. To perform something similar using AngularJS, this is how we do it.
function authenticateUser(username, authtoken) {
  var url = ""

  var credentials = btoa(username + ':' + authtoken);
  var authorization = {'Authorization': 'Basic ' + credentials};
  var header = { headers: authorization }

  return $http.get(url, header)
     .then( function(response) {
In the code above, I encoded the username, and authtoken to base64 using btoa(). Then, I added that to the auth header, which then gets attached to our get() request. So easy right?

How to Deploy your Meteor app to a Custom Subdomain

Deploying your meteor app to a custom subdomain is really simple. In this example, I will try to deploy to The command for deploying is written below, run that on your terminal and wait for it to finish.
meteor deploy

Done? Now open your domain registrar of choice, in this example I'll be using namecheap. In the All host records tab, use the following values to fill up the form:

Host Name IP Address/URL Record Type TTL
@ URL Redirect 1800
www CNAME(Alias) 1800
myapp CNAME(Alias) 1800
www.myapp CNAME(Alias) 1800

Here is a screenshot for further clarification:

That's it! Visit the page and it should be good to go! :D

How to make or register a service in Ubuntu 14.04 (Trusty)

Registering a service in Ubuntu is really simple. In this tutorial, I am using Ubuntu 14.04. The steps should be quite similar across different versions. So let's get started.

1. Prepare your script.
Your script can be anything really. In this tutorial, I'll be using a very simple script which starts/stops apache2 and it looks some what like this:
case "$1" in
echo "Starting Apache ..."
# Change the location to your specific location
/usr/local/apache2/bin/apachectl start
echo "Stopping Apache ..."
# Change the location to your specific location
/usr/local/apache2/bin/apachectl stop
echo "Restarting Apache gracefully..."
# Change the location to your specific location
/usr/local/apache2/bin/apachectl graceful
echo "Restarting Apache ..."
# Change the location to your specific location
/usr/local/apache2/bin/apachectl restart
echo "Usage: '$0' {start|stop|restart|graceful}"
exit 1
exit 0

The file above accepts 4 parameters (start, stop, restart and graceful). I saved the file as apache2.

2. Test your file.
You should be able to test your file by simply running it, see if you have the correct config/folders and such. For example, to run the file above I would simply type the following command on the terminal:
chmod +x
sudo ./apache2 start
3. Move or copy the file to /etc/init.d/
sudo mv apache2 /etc/init.d/
4. Test it again, but this time, as a service.
sudo service apache2 start

And that's it! We're done! Now that wasn't so hard was it? :)


© 2013 icodeya. All rights resevered.Designed by Templateism

Back To Top