Web Developer Weekly: JS Frameworks and Ruby

Every week, I plan to publish an article to highlight the newest news about web development. Let’s face it! We, as web developers, need to be updated somehow of the latest developments.

We are experiencing the fastest growth in technology the world has ever seen. We cannot afford not to know what’s happening. Especially in the world of web development.

Here is the first batch of developments this week.

Basic Javascript

Dr. Axel Rauschmayer writes a blog post about Javascript. It focuses on getting started with JavaScript as quickly as possible.

AngularJS: An Overview

AngularJS is a JavaScript framework made by Google for building complex client-side applications. I love AngularJS and wish to work with it in some project in the future. Glenn Stovall writes an overview of the framework.

Backbone.js Pts 1 – 5

Backbone. Backbone. Backbone. We can’t get enough of it. Why not? It’s quickly becoming an essential skill in web development today. You can’t go around and not hear about it. MetaCasts offers a paid tutorials for those who want to learn more about Backbone.

Puma vs Phusion Passenger

I honestly haven’t used Puma but I have been using Phusion Passenger as my ruby web server of choice lately. I have no idea what differs between the two. This article points out some differences between the two.

How to install Ruby & Rails with screencasts: Linux, Mac OS X, Windows

I have mostly used Ubuntu and Mac for Rails development. Here’s a screencasts for those Windows fanatics that want to work with Ruby on Rails.

 Practical LS Command Usages

The ls is my most used command when working with files especially working with command line stuff.

ls is a command to list files in Unix and Unix-like operating systems. While, ls on its own is quite useful, there are a few more options you can use to work with ls to make it superb!

Hidden Files

ls -la

The a option makes a list of files include files that are hidden. Files like .htaccess, .rvmrc and .gitignore, which are normally hidden, be seen.

total 80
drwxr-xr-x  23 teejay  staff   782 Jul  9 14:16 .
drwxr-xr-x  54 teejay  staff  1836 Jul  4 15:38 ..
drwxr-xr-x  17 teejay  staff   578 Jul  9 18:13 .git
-rw-r--r--   1 teejay  staff   541 Jul  9 14:16 .gitignore
drwxr-xr-x  12 teejay  staff   408 May 29 09:14 .idea
-rw-r--r--   1 teejay  staff    29 Apr 25 09:53 .rvmrc
-rw-r--r--   1 teejay  staff   352 Jul  9 14:16 Gemfile
-rw-r--r--   1 teejay  staff  2759 Jul  9 14:16 Gemfile.lock
-rw-r--r--   1 teejay  staff    33 Apr 25 01:21 README.md
-rw-r--r--   1 teejay  staff  9220 Apr 25 01:21 README.rdoc
-rw-r--r--   1 teejay  staff   281 Apr 25 01:21 Rakefile
drwxr-xr-x   8 teejay  staff   272 Apr 25 01:21 app
drwxr-xr-x  10 teejay  staff   340 Apr 25 11:04 config
-rw-r--r--   1 teejay  staff   166 Apr 25 01:21 config.ru
drwxr-xr-x   5 teejay  staff   170 Jul  9 14:16 db
drwxr-xr-x   3 teejay  staff   102 Apr 25 01:21 doc
drwxr-xr-x   4 teejay  staff   136 Apr 25 01:21 lib
drwxr-xr-x   4 teejay  staff   136 Apr 25 11:03 log
drwxr-xr-x   7 teejay  staff   238 Apr 25 01:21 public
drwxr-xr-x   3 teejay  staff   102 Apr 25 01:21 script
drwxr-xr-x   8 teejay  staff   272 Apr 25 01:21 test
drwxr-xr-x   6 teejay  staff   204 Apr 25 11:03 tmp
drwxr-xr-x   4 teejay  staff   136 Apr 25 01:21 vendor

Human readable format

ls -h

The -h option makes a small formatting change to the filesize of files

total 64
-rw-r--r--   1 teejay  staff   352B Jul  9 14:16 Gemfile
-rw-r--r--   1 teejay  staff   2.7K Jul  9 14:16 Gemfile.lock
-rw-r--r--   1 teejay  staff    33B Apr 25 01:21 README.md
-rw-r--r--   1 teejay  staff   9.0K Apr 25 01:21 README.rdoc
-rw-r--r--   1 teejay  staff   281B Apr 25 01:21 Rakefile
drwxr-xr-x   8 teejay  staff   272B Apr 25 01:21 app
drwxr-xr-x  10 teejay  staff   340B Apr 25 11:04 config
-rw-r--r--   1 teejay  staff   166B Apr 25 01:21 config.ru
drwxr-xr-x   5 teejay  staff   170B Jul  9 14:16 db
drwxr-xr-x   3 teejay  staff   102B Apr 25 01:21 doc
drwxr-xr-x   4 teejay  staff   136B Apr 25 01:21 lib
drwxr-xr-x   4 teejay  staff   136B Apr 25 11:03 log
drwxr-xr-x   7 teejay  staff   238B Apr 25 01:21 public
drwxr-xr-x   3 teejay  staff   102B Apr 25 01:21 script
drwxr-xr-x   8 teejay  staff   272B Apr 25 01:21 test
drwxr-xr-x   6 teejay  staff   204B Apr 25 11:03 tmp
drwxr-xr-x   4 teejay  staff   136B Apr 25 01:21 vendor

Order by Date Modified

The -t is useful if you want to see the last modified files first.

ls -lt
total 64
-rw-r--r--   1 teejay  staff   352 Jul  9 14:16 Gemfile
-rw-r--r--   1 teejay  staff  2759 Jul  9 14:16 Gemfile.lock
drwxr-xr-x   5 teejay  staff   170 Jul  9 14:16 db
drwxr-xr-x  10 teejay  staff   340 Apr 25 11:04 config
drwxr-xr-x   4 teejay  staff   136 Apr 25 11:03 log
drwxr-xr-x   6 teejay  staff   204 Apr 25 11:03 tmp
-rw-r--r--   1 teejay  staff    33 Apr 25 01:21 README.md
-rw-r--r--   1 teejay  staff  9220 Apr 25 01:21 README.rdoc
-rw-r--r--   1 teejay  staff   281 Apr 25 01:21 Rakefile
drwxr-xr-x   8 teejay  staff   272 Apr 25 01:21 app
-rw-r--r--   1 teejay  staff   166 Apr 25 01:21 config.ru
drwxr-xr-x   3 teejay  staff   102 Apr 25 01:21 doc
drwxr-xr-x   4 teejay  staff   136 Apr 25 01:21 lib
drwxr-xr-x   7 teejay  staff   238 Apr 25 01:21 public
drwxr-xr-x   3 teejay  staff   102 Apr 25 01:21 script
drwxr-xr-x   8 teejay  staff   272 Apr 25 01:21 test
drwxr-xr-x   4 teejay  staff   136 Apr 25 01:21 vendor

Order by Date Modifed(Reverse)

-t accompanied by -r reverses the order by making the last modified file last.

ls -lt
total 64
drwxr-xr-x   4 teejay  staff   136 Apr 25 01:21 vendor
drwxr-xr-x   8 teejay  staff   272 Apr 25 01:21 test
drwxr-xr-x   3 teejay  staff   102 Apr 25 01:21 script
drwxr-xr-x   7 teejay  staff   238 Apr 25 01:21 public
drwxr-xr-x   4 teejay  staff   136 Apr 25 01:21 lib
drwxr-xr-x   3 teejay  staff   102 Apr 25 01:21 doc
-rw-r--r--   1 teejay  staff   166 Apr 25 01:21 config.ru
drwxr-xr-x   8 teejay  staff   272 Apr 25 01:21 app
-rw-r--r--   1 teejay  staff   281 Apr 25 01:21 Rakefile
-rw-r--r--   1 teejay  staff  9220 Apr 25 01:21 README.rdoc
-rw-r--r--   1 teejay  staff    33 Apr 25 01:21 README.md
drwxr-xr-x   6 teejay  staff   204 Apr 25 11:03 tmp
drwxr-xr-x   4 teejay  staff   136 Apr 25 11:03 log
drwxr-xr-x  10 teejay  staff   340 Apr 25 11:04 config
drwxr-xr-x   5 teejay  staff   170 Jul  9 14:16 db
-rw-r--r--   1 teejay  staff  2759 Jul  9 14:16 Gemfile.lock
-rw-r--r--   1 teejay  staff   352 Jul  9 14:16 Gemfile

List Files (No other information)

ls -1
Gemfile
Gemfile.lock
README.md
README.rdoc
Rakefile
app
config
config.ru
db
doc
lib
log
public
script
test
tmp
vendor

Comma separated list of files (No other information)

ls -lm
Capfile, Gemfile, Gemfile.lock, Guardfile, README.md, README.rdoc, Rakefile, app, config, config.ru, db, doc, lib, log, public, script, spec, test, tmp, 
vendor

 Display a Calendar in the Terminal Window

How Do I Display a Calendar in the Terminal Window

For those who love the command line, the cal command helps display a calendar. It can show the calendar in a variety of ways like yearly or monthly.

Show the current month Code:
cal

Result:

     July 2013
Su Mo Tu We Th Fr Sa
    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
28 29 30 31
Show a specific month

Code:

cal 08 1983

Result:

    August 1983
Su Mo Tu We Th Fr Sa
    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
28 29 30 31
Show the current year

Code:

cal -y 2013

Result:

                            2013
      January               February               March
Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
       1  2  3  4  5                  1  2                  1  2
 6  7  8  9 10 11 12   3  4  5  6  7  8  9   3  4  5  6  7  8  9
13 14 15 16 17 18 19  10 11 12 13 14 15 16  10 11 12 13 14 15 16
20 21 22 23 24 25 26  17 18 19 20 21 22 23  17 18 19 20 21 22 23
27 28 29 30 31        24 25 26 27 28        24 25 26 27 28 29 30
                                            31
       April                  May                   June
Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6            1  2  3  4                     1
 7  8  9 10 11 12 13   5  6  7  8  9 10 11   2  3  4  5  6  7  8
14 15 16 17 18 19 20  12 13 14 15 16 17 18   9 10 11 12 13 14 15
21 22 23 24 25 26 27  19 20 21 22 23 24 25  16 17 18 19 20 21 22
28 29 30              26 27 28 29 30 31     23 24 25 26 27 28 29
                                            30
        July                 August              September
Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6               1  2  3   1  2  3  4  5  6  7
 7  8  9 10 11 12 13   4  5  6  7  8  9 10   8  9 10 11 12 13 14
14 15 16 17 18 19 20  11 12 13 14 15 16 17  15 16 17 18 19 20 21
21 22 23 24 25 26 27  18 19 20 21 22 23 24  22 23 24 25 26 27 28
28 29 30 31           25 26 27 28 29 30 31  29 30                                            
      October               November              December
Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
       1  2  3  4  5                  1  2   1  2  3  4  5  6  7
 6  7  8  9 10 11 12   3  4  5  6  7  8  9   8  9 10 11 12 13 14
13 14 15 16 17 18 19  10 11 12 13 14 15 16  15 16 17 18 19 20 21
20 21 22 23 24 25 26  17 18 19 20 21 22 23  22 23 24 25 26 27 28
27 28 29 30 31        24 25 26 27 28 29 30  29 30 31

 Deploying a Rails application on CentOS

I love Ubuntu. “Why not?”, you may ask. Well, the only reason is that I have worked almost exclusively with Ubuntu when deploying Rails applications.

Aside from the point that it’s easier and most tutorials on the internet involve Ubuntu deployment, at my current company, we only use Ubuntu on our staging and production server.

I always had the notion that deployment on other Linux distributions would be hard. It turns out, they may not be that different at all. Here’s the deployment recipe I’m using to deploy on CentOS 6.

Update CentOS

yum update

Install requirements

yum -y groupinstall "Development Tools"

groupinstall "Development Tools" will install necessary tools to create a basic development environment. Next step would be to make sure we don’t miss out on some other tools.

yum -y install ntp zlib zlib-devel sqlite-devel httpd mysql-server mysql-devel curl-devel httpd-devel apr-devel apr-util-devel mlocate manlibxml2-devel libxslt-devel libffi-devel readline-devel gcc gcc-c++ make openssl-devel sqlite-devel
/etc/init.d/ntpd stop
ntpdate pool.ntp.org
/etc/init.d/ntpd start
chkconfig ntpd on

Install Ruby

We are using ruby version 1.9.3 because Passenger 4.0 can’t work with 2.0.0 yet.

wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p429.tar.gz
tar zxf ruby-1.9.3-p429.tar.gz
cd ruby-1.9.3-p429
./configure
make
make install
cd ext/openssl
ruby extconf.rb
make
make install
cd ../zlib
ruby extconf.rb
make
make install
cd ../readline
ruby extconf.rb
make
make install
cd
gem update --system
Hiccups

If you are presented by this error:

It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.

A simple fix would be to install libyaml.

curl -O http://www6.atomicorp.com/channels/atomic/centos/6/x86_64/RPMS/atomic-release-1.0-14.el6.art.noarch.rpm
sudo  rpm -Uvh atomic-release-1.0-14.el6.art.noarch.rpm
sudo yum install libyaml-devel

And then reinstall Ruby.

Install Rails and Passenger

gem install rails passenger

Install the Passenger and Apache module

passenger-install-apache2-module

After installation, you will be presented by some text(see below) you need to add to your Apache config file, which can be found here, /etc/httpd/conf/httpd.conf.

Load Module
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.5/libout/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-4.0.5
PassengerDefaultRuby /usr/local/bin/ruby

You will also be presented by an Apache configuration file that you can modify and use for your virtual host

Virtual Host file
<VirtualHost *:80>
    ServerName www.yourhost.com
    # !!! Be sure to point DocumentRoot to 'public'!
    DocumentRoot /somewhere/public    
    <Directory /somewhere/public>
       # This relaxes Apache security settings.
       AllowOverride all
       # MultiViews must be turned off.
       Options -MultiViews
    </Directory>
 </VirtualHost>

Restart Apache

Now if everything goes well, you can restart Apache.

Visit your url and voila! A newly deployed Rails Application!

Visit the Passenger site for more Information about Deploying Rails with Passenger on Apache