Showing posts with label basic shell. Show all posts
Showing posts with label basic shell. Show all posts

Monday, September 7, 2015

Installing and Using Ruby Interactive Shell on Windows

      Ruby is dynamic,interpreted, object oriented programming languages which is one of the easiest programming language to learn and with Rails its just might be the best web development option at the moment. Ruby intsallation is pretty much simple in windows, Linux and you don't have to install Ruby on Mac. It already has Ruby installed in it.

   Step by step guide to install Ruby on your PC:
  1. Go to Ruby programming language homepage: https://www.ruby-lang.org/en/
  2. Click downloads
  3. Click on Installation-->click on RubyInstaller(Windows)-->Ruby installer-->Download
  4. Select the top selection there that will be the current version of Ruby 
  5. Click save file. let it download
  6. Now double click the file-->accept license agreement-->Install-->finish.

Using Ruby Interactive Shell 

        The interactive shell  or just a shell allows us to type Ruby statements or expressions at the command line and gives immediate result. So open the command prompt and navigate to the folder where Ruby is installed and type "irb".


On ruby shell single number evaluates itself. We can perform simple arithmetic operations the ways show above screenshot. Strings also evaluate to them self, We can perform concatenation operation between two strings using '+' operator as shown below :


     
         We can also store data in variables and use it later as shown in below "greet' is variable which stores value "good morning". After typing good morning it returns "good morning".


   We can also concatenation "greet" with other value 


    We can write more complicated expressions in ruby shell. We can create functions for example square function in bellow example. Here I wrote my own user define "sqr" function to find square of a number.
 
   
     If you have good understanding of function you not even have to write return statement. lets consider following function for addition of two numbers. In which I wrote add method for addition of two numbers when next time I write add(2,2)  it performs addition of these two numbers which is 2+2=4.



Tuesday, March 31, 2015

MongoDB find() and findOne() methods



     In  MongoDB CRUD operation find() and findOne() methods are used to read a documents from the collections. Lets study this methods with example. 

1. find() : 
                  The most basic operation to query documents out of the database is called find(). MongoDB find() method returns all documents present in the database.
 For example, Here I have student database and collection name is grades which has 800 documents. After executing this query it returns first 10 documents and it ask for next 10 documents. If you want more documents type "it" next 10 documents will get display.

    find() method can take some arguments. You can filter result by adding search criteria. For example in "grades" collection there are "homework","quiz" and "exam " type of documents. If I want only "exam" type . The query will be db.grades.find({''type'' :''exam''}).




       We can also add multiple fields in criteria but both the criteria should match. Like here I have selected students with type :exam and you can also include and exclude fields if you want by making field name true or false, here I excluded object id field.





  2. findOne():

 This method also retrieves the data but it returns only one document at a time. Lets see following example fineOne() without argument returns very first document from the collection.



  We can also add criteria in findOne() method like find() method. In following example only document with the "student_id" : 112 is return as specified in criteria.




         









Tuesday, February 5, 2013

Understanding basic shell commands of Linux



Understanding basic shell commands of Linux:-

Shell:-
The shell act's as the most powerful interaction between user and the kernel in system. The shell is a command line interpreter, it interprets the user typed commands in console of terminal.
There are various types of shells are available, which are as follows:
       Bourne shell
       C shell
       Korn shell
       Bash shell
Let's discuss some basic shell commands:-
pwd:
The shell command “pwd” prints the current working directory. That means if you are working in home it will display “/home”.
Ex:ravi@ravi:~$ pwd
/home/ravi
cd:
The shell command “cd” allows us to change the directory. We have to move to particular directory to access the contents in it or by specifying explicit  path of a file, so we can access any file.
Ex:
ravi@ravi:~$ cd Downloads
ravi@ravi:~/Downloads$
cat:
The shell command “cat” displays the contents of file in console.
Ex:
ravi@ravi:~$ cat workshop
Displays the contents of file workshop
rm:
The shell command “rm” allows us to remove the file from current directory.          
Ex:
ravi@ravi:~$ rm unixfile
After executing this command the file “unixfile” is removed or deleted.
rmdir:
The shell command “rmdir” allows us to remove the directory from current directory.
Ex:
ravi@ravi:~$ rmdir directory
After executing this command the directory named “directory” is removed from current directory.
touch:
The shell command “touch” allows us to create file in current directory.
Ex:
ravi@ravi:~$ touch newfile
After executing this command the file “newfile” is created in current directory.
mkdir:
The shell command “mkdir” allows us to create directory in current directory.
Ex:
ravi@ravi:~$ mkdir newdir
After executing this command the directory newdir.
nautilus:
The shell command “nautilus”  allows us to show the home window.
Ex:
ravi@ravi:~$ nautilus
ps:
The shell command “ps” allows us to show the current running process started by the user.
Ex:
ravi@ravi:~$ ps
PID TTY          TIME CMD
3795 pts/0    00:00:00 bash
4867 pts/0    00:00:00 ps
top:
The shell command “top” allows us to show the all the daemon process.
Ex:
ravi@ravi:~$ top
ls:
The shell command “ls” allows us to show the contents of current directory.
Ex:ravi@ravi:~$ ls