Sunday, September 14, 2014

Responsive design

After reading and referring to lot of blogs, the following piece of code that I compiled serves for a lot of devices.

Blog that I referred is

/* Apple iphone 4 & 5, Nexus S */
@media only screen and (max-width : 321px){


/* HTC One X, Evo LTE, Google Nexus 4, 5, Samsung Galaxy Note II */
@media only screen and (min-width: 322px) and (max-width : 384px){


/* LG Optimus LTE, Motorola Droid 3,4, Samsung galaxy Note, Note III*/
@media only screen and (min-width: 385px) and (max-width : 541px){


/* Apple Ipad 1, 2, Mini, 3, 4, Nexus 7 2, Nexus 7, Blackberry Playbook */
@media only screen and (min-width: 542px) and (max-width : 1024px) {

/* Desktops and laptops, Google Nexus 10 */
@media only screen and (min-width: 1224px) {


The above code worked for me and might not completely work for you in all cases. Please do let me know if there needs to be any changes.

Saturday, August 4, 2012

Web interactive shell using node.js

I am pretty sure most of you (developers) are totally in love with the terminal or command-line. Using the terminal makes you cool because of the simple reason that you do not use the mouse and complete everything with they keyboard. How cool is that ?!

Have you ever imagined how interesting it would be to use the same terminal from the browser as a web application ? Well its beautiful too, but the catch here is that developing this would be kind of tough. Believe me with the introduction of node.js things are very easy.

In this post I will be discussing how easy it is to develop a web interactive shell using node.js

1. You are a basic terminal user.
2. You know the basics of node.js
3. You have node.js installed.

Technical Assumptions:
1. You have express and modules installed

Now that node.js is up and running at say port 4990.

The below part is a the server side stuff which use a child process to execute the commands you send to it.

var app require('express').createServer(),
    io require('').listen(app),
    sys require('util'),
    exec require('child_process').exec;



        function puts(errorstdoutstderr{

The below is the client side stuff which connects to node server, opens a socket and sends information over the socket. What is nodestrap[1] ?

            // response from the server which is the result of the commands

This is used to send the message over the socket from client to server side.

    var msg {};
    msg.command 'ls -al'

[1] : nodestrap is my own plugin which helps the client side in connecting to the node server. The details will be available in the following blog.

I hope this helps you to create a simple web interactive shells. Please improvise ;)

Saturday, July 21, 2012

Setting up AWS EC2 instance

For those who have no clue about what cloud is and what AWS does, simple, you also know that your personal computer is not a super machine and does not have super processing power, Amazon Web Services (AWS) to the rescue.

Amazon has machines which are powerful interms of their computing capacity, storage capacity and etc and these are provided as services to common users at low prices. By low they mean, you need to pay per usage

One of the most attractive things about AWS is that they have a free-tier, how cool is that ?

In this blog I'd like to briefly discuss the steps to setup a running instance on AWS.

Step 1: Start an instance

  • You can choose any instance (Linux,Windows,Red hat) and there are instances which come under free tier as well.
  • After selecting an instance, instance type is to be selected (Micro, Small, High-CPU Medium, Medium. Again (Micro is an instance which fall under the free-tier).
    • Availability zone need not be chosen unless you want the instance to run in a particular region.
  • Defaults can be chose in the next step. (Kernel ID and Ram Disk ID).
  • Tags in the form Key value pairs are to be created.
  • ! Important step, a new key pair or an existing key pair has to be selected for the current instance. Key pair file once lost cannot be downloaded again, so please be extremely careful.
  • Security group for the instance is created. A security group is a set of rules which enable the user to communicate with the instance. Ex: TCP/HTTP/HTTPS/FTP/SSH ports are defined.
    • A sample group can contain the following rules,
      SSH - for connecting to the instance using sftp, ssh
      HTTP - for opening port 80 for the webserver to serve content.
      MY SQL - if you are using RDS
  • Launch and you are done ! 
  • An instance usually takes about 2-3 mins the start.
Step 2: Install stack (LAMP)

Now that the instance is ready, we need a stack for the server to serve pages to user.
Personal choice would be LAMP (Linux Apache MySQL PHP).
The following block of code will install the required dependencies and lamp stack.

Firstly, in order to connect to the instance, ssh from terminal (for mac/linux users) or git bash for windows users needs to be used. The instructions to connect to the instance is provided in amazon management console.

After successfully loggin to the account, firstly upgrade to root user by sudo -i.

Installing services

yum install httpd -y
service httpd start
yum install php libmcrypt libmcrypt-devel php-mcrypt php-mbstring php-mysql -y
service httpd restart
yum install mysql -y
yum install mysql-server -y
service mysqld start
/usr/bin/mysqladmin -u root password

Installing phpmyadmin

cd /var/www/html
tar -xzvf phpMyAdmin- -C /var/www/html
mv phpMyAdmin- phpmyadmin
rm -rf phpMyAdmin-
adduser phpmyadmin
passwd phpmyadmin
chown -R phpmyadmin.apache phpmyadmin/
cd /var/www/html/phpmyadmin/
mkdir config
chmod o+rw config
cp config/
chmod o+w config/
service httpd restart
Browse to: http://YOUR_SERVER_IP/phpmyadmin/setup/index.php

Disable Directory listing

vim /etc/httpd/conf/httpd.conf

Options All -Indexes

Mount EBS volume

mkfs.ext3 /dev/sdf
mkdir /ebs
mount -t ext3 /dev/sdf /ebs
/sbin/service httpd stop
mv /etc/httpd /ebs/httpd
ln -s /ebs/httpd /etc
mv /var/www /ebs/www
ln -s /ebs/www /var/
/sbin/service httpd start

/sbin/service mysqld stop
mkdir /ebs/mysql
cd /ebs/mysql
mkdir lib log
mv /var/lib/mysql /ebs/mysql/lib
mkdir /var/lib/mysql
chown mysql:mysql /var/lib/mysql
mv /var/log/mysqld.log /ebs/mysql/log/
vim /etc/my.cnf

comment datadir & log-error and replace with below
datadir =/ebs/mysql/lib/mysql

/sbin/service mysqld start

vim /etc/fstab
/dev/sdf /ebs ext3 defaults 1 1

(In above statement the mounted volumes is made to mount automatically)

Include swapspace

dd if=/dev/zero of=/swapfile bs=1M count=1024
mkswap  /swapfile
swapon /swapfile
/swapfile swap swap defaults 0 0

Including swap space will increase the performance of the instance.

Auto load on boot

chkconfig httpd on
chkconfig mysqld on

The above statements will start httpd and mysqld service automatically on restarting the instance.