Wednesday 9 April 2014

Using FTP on mobile.

File Transfer Protocol (FTP) is a standard network protocol used to transfer files from one host to another host over a TCP-based network, such as the Internet.
FTP is built on a client-server architecture and uses separate control and data connections between the client and the server.[1] FTP users may authenticate themselves using aclear-text sign-in protocol, normally in the form of a username and password, but can connect anonymously if the server is configured to allow it.
This article is about using this protocol on mobile. The need arises when one wants to share his/her files on computer with mobile and vice-versa. FTP can be a life-saver when you have lost your data transfer cable and your bluetooth is not working for some reason.
For this we we need a FTP client which will be installed on the computer. Linux users have built-in ftp command utility.
Window users can download FileZilla(Download Here).
FileZilla is an easy-to-use GUI and doesnt require a whole a new article to be written about its usage.
Go to their wiki : Using FileZilla
Now you have to install FTPDroid(Download here) on your mobile to make it a ftp server. Run this app and get your IP address.
Now I' ll describe few commands for using  ftp on linux.
Let's say you want to connect to the mobile with IP 192.168.2.13
At the command line, type:

ashu@like-a-boss:ftp
         Now type open:
ftp>open 
  Now you will be prompted to enter IP address of mobile.
         ftp > open
         (to)  192.168.2.13
Press enter and then enter your username and password configured on FTPDroid.
        Connected to 192.168.43.1.
       220---------- Welcome to Pure-FTPd [TLS] ----------
      220-You are user number 1 of 50 allowed.
      220-Local time is now 22:57. Server port: 21.
      220-IPv6 connections are also welcome on this server.
      220 You will be disconnected after 15 minutes of inactivity.
      Name (192.168.43.1:ashu):ashu 
      Password:
After authentication,
     230 OK. Current directory is /mnt/sdcard
    Remote system type is UNIX.
    Using binary mode to transfer files.
    ftp> 
Now you can enter commands to play up and down the directory in your mobile file system. You may also download or upload files on from/to the server.

ls - To list all the files on the remote server(mobile).
cd - To change directory on remote server.
lcd -  To change directory on local system.
get - To download file from the server( get <file-name>)
put - To upload file on the server( put <file-name>)
mget/mput - To download/upload multiple files from/on the server( mget/mput <file-name>)

The ftp client supports using the bang (!) to run local commands. For example, to get a listing of files in your current local directory, do this:

ftp> !ls
Wouldn't it be nice if you could watch the progress while you're downloading a file with ftp? You can use the hash command to print out hash marks as you download a file:

ftp> hash
Hash mark printing on (1024 bytes/hash mark).

As you can tell, ftp will print a hash mark for every 1024 bytes of data you download.

There is also a tick option.

ftp> tick           
Tick counter printing on (10240 bytes/tick increment).

This will print something to this effect as you download a file:
 
Bytes transferred: 11680 


Monday 7 April 2014

Focus Booster : The Pomodoro Technique

The pomodoro technique is a time management technique which  allows you to work with time, using time to your advantage to stay fresh, remove distractions and create a better work life balance. The pomodoro technique uses a timer to break down periods of work into 25-minute intervals (referred to as ‘pomodoros’ or ‘pomodoro sessions’). These intervals are separated by breaks (the standard is 5 minutes). Pomodoro time management is based on the theory that frequent breaks can improve mental agility. I can vouch for that!

How do you implement the pomodoro technique?

Here are the five basic steps to implementing pomodoro time management;

- decide on the focus task.
- set the pomodoro timer to 25 minutes.
- work on the task until the timer rings.
- take a short break (5 minutes), keep note of the number of session you complete.
- every 4 sessions take a longer break, perhaps 15 or 20 minutes. 

Who is the pomodoro technique best for?

If you want to be more productive, then pomodoro is a technique for you. It is a fail proof time management technique and the implementation of a digital timer makes it even more simple.

Here are a few of the regular adopters of the focus booster technique we come across;

- freelancers
- students
- developers
- managers
- specialists performing consultations in scheduled timeframes (for example psychologists)
- writers

  So, If You are one of them or You want to be more productive, shift your focus to this Focus booster technique and see how your concentration and work level increases!


Sunday 23 February 2014

Linux File Permissions

All file system objects on Unix-like systems have three main types of permissions: read, write, and execute access. Furthermore, permissions are bestowed upon three possible classes: the user that owns the file system object, the user group that owns the file system object, and all system users. To view the file permissions of a set of files, use the ls -lha command. The output will resemble the following:
drwxr-xr-x 2 squire squire       4.0K 2009-08-13 10:16 docs
-rw-r--r-- 1 squire squire       8.1K 2009-07-09 16:23 roster.py
lrwxrwxrwx 2 squire squire       4.0K 2009-08-13 10:16 team.docs
The first block of data contains information regarding the file permissions and settings, and we'll focus on that in this section. The first column specifies the type of file system object. d indicates that the object is a directory. - indicates that the object is a normal file. l indicates that the object is a symbolic link.
The remaining characters represent the core permissions. In groupings of three, these characters represent read, write, and execute permissions. The first grouping represents the owners permissions, the second grouping represents the usergroup that owns the file, and the final grouping represents the permissions of all users on the system.
Any object on the file system may have any combination of permissions. Note, access to the files targeted by symbolic links is controlled by the permissions of the targeted file, not the permissions of the link object. There are additional file permissions that control other aspects of access to files.

The Chmod Command

Consider the following invocation of chmod:
chmod g+w ~/group-project.txt
This grants all members of the usergroup that owns the file ~/group-project.txt write permissions. To remove this permission later, switch the + sign to a -, as in the following example.


chmod g+w,o-rw,a+x ~/group-project-files/
chmod g-w ~/group-project.txt
You can specify multiple permissions by separating them with a comma, as in the following example:
This adds write permissions to the usergroup members, and removes read and write permissions from the "other" users of the system. Finally the a+x adds the execute permissions to all categories. This value may also be specified as +x. If no category is specified, the permission is added or subtracted to all permission categories. In this notation the owner of the file is referred to as the user (e.g. "u+x").


chmod -R +w,g=rw,o-rw, ~/group-project-files/
The -R option applies the modification to the permissions recursively to the directory specified and all of its contents. You may also specify file permissions using the = sign rather than the + or - operators to signify only the specified permissions if you need to specify a set of permissions without relation to the current state of the file's permission.


The notation used in this document thus far can be confusing for particularly complex file permission requirements. chmod provides an alternate "octal" notation that you may find more sensible:
0 ---      indicates no permissions
1 --x      indicates execute permissions
2 -w-      indicates write permissions
3 -wx      indicates write and execute permissions
4 r--      indicates read permissions
5 r-x      indicates read and execute permissions
6 rw-      indicates read and write permissions
7 rwx      indicates read, write, and execute permissions

Getting the C++ output on browser

You write some C++ code,  compile it and get your output on black screen. Too mainstream, right!
Here's a trick...what if you can take your output to your web-browser. Of-course you have to take the extra pain but it'll be worth it.
The audacity to speak above lines are given to me by something called "CGI". So what is CGI?

  • The Common Gateway Interface, or CGI, is a set of standards that define how information is exchanged between the web server and a custom script.
  • The CGI specs are currently maintained by the NCSA and NCSA defines CGI is as follows:
  • The Common Gateway Interface, or CGI, is a standard for external gateway programs to interface with information servers such as HTTP servers.
  • The current version is CGI/1.1 and CGI/1.2 is under progress.

I know that was too much , so here is how CGI actually works:

  • To understand the concept of CGI, let's see what happens when we click a hyperlink to browse a particular web page or URL.
  • Your browser contacts the HTTP web server and demand for the URL ie. filename.
  • Web Server will parse the URL and will look for the filename. If it finds requested file then web server sends that file back to the browser otherwise sends an error message indicating that you have requested a wrong file.
  • Web browser takes response from web server and displays either the received file or error message based on the received response.
However, it is possible to set up the HTTP server in such a way that whenever a file in a certain directory is requested, that file is not sent back; instead it is executed as a program, and produced output from the program is sent back to your browser to display.

The Common Gateway Interface (CGI) is a standard protocol for enabling applications (called CGI programs or CGI scripts) to interact with Web servers and with clients. These CGI programs can be a written in Python, PERL, Shell, C or C++ etc.

Web Server Configuration

Before you proceed with CGI Programming, make sure that your Web Server supports CGI and it is configured to handle CGI Programs. All the CGI Programs to be executed by the HTTP server are kept in a pre-configured directory. This directory is called CGI directory and by convention it is named as /var/www/cgi-bin. By convention CGI files will have extension as .cgi, though they are C++ executable.
By default, Apache Web Server is configured to run CGI programs in /var/www/cgi-bin. If you want to specify any other directory to run your CGI scripts, you can modify the following section in the httpd.conf file:
<Directory "/var/www/cgi-bin">
   AllowOverride None
   Options ExecCGI
   Order allow,deny
   Allow from all
</Directory>
 
<Directory "/var/www/cgi-bin">
Options All
</Directory>
Here, I assumed that you have Web Server up and running successfully and you are able to run any other CGI program like Perl or Shell etc.

First CGI Program

Consider the following C++ Program content:
#include <iostream>
using namespace std;
 
int main ()
{
    
   cout << "Content-type:text/html\r\n\r\n";
   cout << "<html>\n";
   cout << "<head>\n";
   cout << "<title>Hello World - First CGI Program</title>\n";
   cout << "</head>\n";
   cout << "<body>\n";
   cout << "<h2>Hello World! This is my first CGI program</h2>\n";
   cout << "</body>\n";
   cout << "</html>\n";
   
   return 0;
}

Compile above code and name the executable as cplusplus.cgi. This file is being kept in /var/www/cgi-bin directory and it has following content. Before running your CGI program make sure you have change mode of file using chmod 755 cplusplus.cgi UNIX command to make file executable. Now if you click cplusplus.cgi then this produces the following output:

Hello World! This is my first CGI program

Unblocking the Hard-block wireless in ubuntu

Sometimes we come across an awkward situation where our wifi or bluetooth are "on" but still they dont work. In such a case , your wireless may be "hard-blocked". Summon the Terminal and let issue the following commands:

me@ubuntu:~$ rfkill list all
1: phy0: Wireless LAN
Soft blocked: no
Hard blocked: no
2: brcmwl-0: Wireless LAN
Soft blocked: yes
Hard blocked: no
3: hci0: Bluetooth
Soft blocked: yes
Hard blocked: no

To unblock all the wireless , type in:

me@ubuntu:~$ rfkill unblock all

And bamm!! your problem is solved. Happy life :)




Packages and Repositories

If we spend any time in the Linux community, we hear many opinions as to which of the
many Linux distributions is “best.” Often, these discussions get really silly, focusing on
such things as the prettiness of the desktop background (some people won't use Ubuntu
because its default color scheme is brown!) and other trivial matters.
The most important determinant of distribution quality is the packaging system and the
vitality of the distribution's support community. As we spend more time with Linux, we
see that its software landscape is extremely dynamic. Things are constantly changing.
Most of the top-tier Linux distributions release new versions every six months and many
individual program updates every day. To keep up with this blizzard of software, we
need good tools for package management.
Package management is a method of installing and maintaining software on the system.
Today, most people can satisfy all of their software needs by installing packages from
their Linux distributor. This contrasts with the early days of Linux, when one had to
download and compile source code in order to install software. Not that there is anything
wrong with compiling source code; in fact, having access to source code is the great
wonder of Linux. It gives us (and everybody else) the ability to examine and improve the
system. It's just that having a pre-compiled package is faster and easier to deal with.

Package Files
The basic unit of software in a packaging system is the package file. A package file is a
compressed collection of files that comprise the software package. A package may
consist of numerous programs and data files that support the programs. In addition to the
files to be installed, the package file also includes metadata about the package, such as a
text description of the package and its contents. Additionally, many packages contain
pre- and post-installation scripts that perform configuration tasks before and after the
package installation.

To install a package ,type in the following command:

[me@ubuntu ]$: sudo apt-get install <package-name>

Repositories
"A repository is a central place where data is stored and maintained. A repository can be a place where multiple databases or files are located for distribution over a network, or a repository can be a location that is directly accessible to the user without having to travel across a network." says the Wikipedia

A repository is simply a collection of package files hosted on arbitrary server.
To add a repository,type in the terminal:

[me@ubuntu ]$: sudo add-apt-repository <repository-name>

Compiling c++ program using linux terminal

C++ is the most widely taught programming language to students .Getting your c++ code to work desirably requires it to be compiled without any errors. Windows users who have shifted to Linux are habitual to GUIs compiler like geany,code-blocks,visual c++ etc and have no idea where to compile their c++ code. Our beloved Terminal comes to the rescue of these linux newbies. Its as simple as writing two lines of commands. First you need to install the compiler called g++. Fire up the terminal and type in following commands.
To install g++,type:

[me@linuxbox]$ sudo apt-get install build-essential

This command installs other essential packages too. Alternatively, you may also try:

[me@linuxbox usr]$ sudo apt-get install g++
  
Thats it, you're good to go with your c++ code. Suppose you have a file called hello.cpp. To compile this program , type in:

[me@linuxbox usr]$ g++ hello.cpp  -o hello

-o option converts the compiled code into executable code and stores it in file "hello". To execute this file , type in:

[me@linuxbox usr]$ ./hello

and you see your output on the terminal itself.