Saturday, December 21, 2013

NMAP

NMAP is an awesome tool for network mapping.

To know more:
1) install nmap
:~$ sudo apt-get install nmap

2) Commands:
for commands type
:~$nmap

The above will list commands available.

3) Great article about nmap commands:
http://www.cyberciti.biz/networking/nmap-command-examples-tutorials/

Network Mapping in Linux

1) How to get Default Gateway in linux:

:~$ route -n

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.3.1   0.0.0.0         UG    0      0        0 wlan0
192.168.3.0     0.0.0.0         255.255.255.0   U     9      0        0 wlan0

Then 192.168.3.1 is the default gateway (which resides in the router)

2) traceroute:

Gives echo response from every networking device that we go through.

e.g.:
~$ traceroute linkedin.com
traceroute to linkedin.com (216.52.242.86), 30 hops max, 60 byte packets
 1  * * *
 2  24.4.96.1 (24.4.96.1)  12.809 ms  18.279 ms  18.287 ms
 3  te-0-2-0-0-ur05.santaclara.ca.sfba.comcast.net (68.85.191.161)  18.279 ms  18.277 ms  18.271 ms
 4  te-1-1-0-10-ar01.sfsutro.ca.sfba.comcast.net (68.87.226.118)  25.134 ms te-1-1-0-1-ar01.sfsutro.ca.sfba.comcast.net (69.139.198.90)  25.115 ms te-1-1-0-0-ar01.sfsutro.ca.sfba.comcast.net (69.139.198.82)  25.056 ms
 5  he-3-8-0-0-cr01.sanjose.ca.ibone.comcast.net (68.86.94.85)  28.455 ms  28.475 ms  28.472 ms
 6  50-242-148-34-static.hfc.comcastbusiness.net (50.242.148.34)  45.187 ms  38.972 ms  37.976 ms
 7  vlan70.csw2.SanJose1.Level3.net (4.69.152.126)  47.620 ms  47.597 ms  47.543 ms
 8  ae-71-71.ebr1.SanJose1.Level3.net (4.69.153.5)  47.486 ms  44.121 ms ae-91-91.ebr1.SanJose1.Level3.net (4.69.153.13)  47.694 ms
 9  ae-2-2.ebr3.LosAngeles1.Level3.net (4.69.132.10)  44.047 ms  44.664 ms  44.634 ms
10  ae-73-73.csw2.LosAngeles1.Level3.net (4.69.137.38)  47.430 ms ae-93-93.csw4.LosAngeles1.Level3.net (4.69.137.46)  45.049 ms ae-63-63.csw1.LosAngeles1.Level3.net (4.69.137.34)  46.555 ms


The above command shows all the routers this command goes through to reach the server for linkedin.com. Above shows that linkedin have their main router in Los Angeles.

3) How to get address resolution protocol address:
~$ arp -n

4)How much time does it take to get response from a server/website:

dig archlinux.org | grep "Query time"

5)Who is on my network??

:~$ whowatch

The above is a utility which tells you people connected to the network.

6) Excellent article on loopback:
http://askubuntu.com/questions/247625/what-is-the-loopback-device-and-how-do-i-use-it

7) how to check devices (hosts) in your network:
nmap -w -sP 192.168.3.100/24
 


Monday, December 16, 2013

Great article about node.js

http://stackoverflow.com/questions/1884724/what-is-node-js

Developing client applications if you detest JavaScript: http://www.gwtproject.org/overview.html

Framework for node.js: http://nodeframework.com/

Communities for node.js:
1) http://gruntjs.com/
2) http://momentjs.com/
3) http://mean.io/


Great web developer:

https://medium.com/what-i-learned-building/905b0d7d15c3
(http://sagiisha.com/)
 

Monday, December 9, 2013

General Ubuntu Commands

1) How to check the type of RAM you have.

$ sudo dmidecode --type 17

Result should be like:

SMBIOS 2.7 present.

Handle 0x0008, DMI type 17, 21 bytes
Memory Device
    Array Handle: 0x0007
    Error Information Handle: Not Provided
    Total Width: 64 bits
    Data Width: 64 bits
    Size: 2048 MB
    Form Factor: SODIMM
    Set: None
    Locator: SODIMM1
    Bank Locator: Bank 0
    Type: DDR3
    Type Detail: Unknown

Handle 0x000A, DMI type 17, 21 bytes
Memory Device
    Array Handle: 0x0007
    Error Information Handle: Not Provided
    Total Width: Unknown
    Data Width: Unknown
    Size: No Module Installed
    Form Factor: SODIMM
    Set: None
    Locator: SODIMM2
    Bank Locator: Bank 1
    Type: Unknown
    Type Detail: Unknown

2. Interesting website which tells you about your memory and other things.
crucial.com

Thursday, November 21, 2013

How to deploy on Heroku

Pr-requisites:

1)Heroku account.
2)Working on RoR.

1) Install Heroku using
https://toolbelt.heroku.com/

2)Login to Heroku
Command: heroku login

3)Once logged in, go to your root file of your application.

4)Add a heroku key.
Command: heroku keys:add

5)Push your code.(considering you are on branch master)
Command: git push heroku master

6)

Saturday, November 16, 2013

Facing issues with ImageMagick

Error which I get is:

identify: no decode delegate for this image format `/tmp/stream20131115-12525-1jng9sh.png' @ error/constitute.c/ReadImage/552

What it means: It means that it does not recognize file type extension "png"

Solution:

I configure ImageMagick so that it is able to recognize png format.

What I did:

Checked the list of formats supported:

identify -list format

Found that jpeg and png were not there.

How to add them.

1) Download jpeg and png from http://www.imagemagick.org/download/delegaetes/
2)Execute "tar -xvf file_name.tar"
   Change directories to the newly created "file_name"
   Execute "./configure"
   Execute "make"
   Execute "make install"

Do the above for both jpeg and png.

3) Now we need to reconfigure ImageMagick:

Go to the folder where you have stored it.
 a) execute ./configure --with-jpeg=yes --with-jp2=yes -with-png=yes
 b) sudo make
 c) sudo make install

After this check whether it is there in DELEGATES.

execute
identify -list format

Both the formats should now be a part of format.

If the above gives error like:

“error while loading shared libraries: libjpeg.so.9: cannot open shared object file: No such file or directory”

execute :
sudo apt-get install libjpeg62


This would solve the problem. Enjoy.





Friday, November 15, 2013

Faced issue with LDAP while testing with Rspec in RoR application

Issue was with tmpdir.

Error:

Cannot guess tmpdir from the environment.  Please specify it.

How to solve this?

Well,

Just add a new variable to your bashrc (environment file in Ubuntu)

e.g.

  export TMPDIR=/tmp


And that's it. This would clear up.

Dont forget to source your bashrc file before running the tests.

For sourcing you do:

source ~/.bashrc

Enjoy!

Directory Tree of Ubuntu

Directory     Content
bin     Essential command binaries
boot     Static files of the boot loader
dev     Device files
etc     Host-specific system configuration
home     User home directories
lib     Essential shared libraries and kernel modules
media     Contains mount points for replaceable media
mnt     Mount point for mounting a file system temporarily
proc     Virtual directory for system information (2.4 and 2.6 kernels)
root     Home directory for the root user
sbin     Essential system binaries
sys     Virtual directory for system information (2.6 kernels)
tmp     Temporary files
usr     Secondary hierarchy
var     Variable data
srv     Data for services provided by the system
opt     Add-on application software packages

Thursday, November 14, 2013

Wednesday, November 13, 2013

What is TCP/IP

End to End connectivity, which specifies

How data is
1)formatted
2)addressed.
3)transmitted
4)routed
5)received
at the destination

It has 4 abstraction layers

1)Link Layer.
2)Internet Layer.
3)Transport Layer.
4)Application Layer.


How to use grep for checking whether files exists or not

1.
find /dir_path -type f -print | grep 'tmpdir' # that will show files what names contain tmpdir

Saturday, November 9, 2013

Git commands

1. 
# Get number of files added to the index (but uncommitted)
expr $(git status --porcelain 2>/dev/null| grep "^M" | wc -l)

# Get number of files that are uncommitted and not added
expr $(git status --porcelain 2>/dev/null| grep "^ M" | wc -l)

# Get number of total uncommited files
expr $(git status --porcelain 2>/dev/null| egrep "^(M| M)" | wc -l)
 
2. Great post
http://stackoverflow.com/questions/2452226/master-branch-and-origin-master-have-diverged-how-to-undiverge-branches
 

Monday, November 4, 2013

Installing Eclipse for Android Development

Steps

1. Install eclipse using Ubuntu Software Center.
2. Install the adt using the >>help>>install new software >> add url
https://dl-ssl.google.com/android/eclipse/
 
And click next>>next

3. Download Android SDK and set the path using preferences in Windows tab.

 

Tuesday, October 15, 2013

BDD and Acceptance Testing with Rspec and Capybara

BDD helps us to figure out
1)What to test. - Use cases or User Stories. Test what something does(behavior) rather than what something is (structure)
2)Where to start. - From the outermost layer.
3)What to ignore.- Ignore the stuff in the middle.

-Notes
 -Proper acceptance test treat your application as a black box. Which means that they should have no knowledge of your application.
 - Capybara is a browser automation library.
- helps you test web applications by stimulating how  areal user would interact with your app.
 - It is agnostic about the driver running your tests and comes with Rack::Test and Selenium support built in.
- Rack::Test run requests against your app, then provides the resulting HRML to capybara and rspec examination.

-When testing
 Remember order for the db commands:

rake db:reset
rake db:migrate
rake db:test:prepare
rake db:populate

Sunday, October 13, 2013

Running PostgreSQL with rails.

1. Run the PostgreSQL by issuing the following command:

$ sudo /etc/init.d/postgresql start

Expected Output:
 * Starting PostgreSQL 9.1 database server

2. Run your Rails Server using the command:

$ rails server

3. To run your database:  psql -U user_name db_name

4. Enjoy.

Notes: When PostgreSQL is configured it creates a configuration file pg_hba.conf. 

Issues faced:

There was a peer authentication error while running the rails server
Solution:
Change the configuration in the PostgreSQL conf file.

i.e. pg_hba.conf
Issue the following command.

$ sudo nano /etc/postgresql/9.1/main/pg_hba.conf

Update the


local all postgres peer
to
local all postgres md5

That would solve the problem with authentication.  

Saturday, October 12, 2013

What is the difference between locally installed and system wide installation of gems.

The locally installed gems ~/.gem are accessible only by the user. Whereas the system wide installation of gem, which is in /usr/lib/ruby can be accessed by everyone.

Installing nokogiri gem for Ruby on Rails project

1. Install
$ sudo apt-get install libxslt-dev libxml2-dev

2.$ sudo gem install nokogiri


Probably you would be able to install nokogiri with the above two steps.

Friday, October 11, 2013

Login Loop after changes to file for including hibernation

If you are trying to login to your system and getting into a loop cycle, then the reason could be the .Xauthority file.

Check the file by issuing the following command:

Alt + Ctrl + F1

Login with your credentials.

$ ls -lah

The .Xauthority file should belong to the user you are trying to login with.

If it is not, probably this is the issue.

Solve it by assigning it to the user you want to login with.

Issue the following command:

$ chown username:username .Xauthority

The above command should solve the issue.


How to install ImageMagick

1. Simply go to the website:

ImageMagick

2. echo Hurray!

Testing in Ruby On Rails

RSpec: Framework to provide testing in Ruby on Rails projects.

Capybara: Provides behavioral testing with Ruby on Rails.

FactoryGirl: Provides data for testing using tools like Capybara.

How to kill a process in Ubuntu

1.Type Top and check all the processes running

2. If you dont' get your process name there.

Then if you know what process you kill.

Use:

(here I want to check any processes with 'jet)

ps -aef | grep mine

You would get something like this:

sony@ubuntu:~$ ps -aef | grep mine
sony      3682     1  0 13:50 ?        00:00:00 /bin/sh /home/sony/Downloads/RubyMine-5.4.3.2.1/bin/rubymine.sh
sony      3747  3682  4 13:50 ?        00:00:10 /usr/lib/jvm/jdk1.7.0_40/bin/java -Xms128m -Xmx512m -XX:MaxPermSize=250m -XX:ReservedCodeCacheSize=64m -XX:+UseCodeCacheFlushing -ea -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -Djb.vmOptionsFile=/home/sony/Downloads/RubyMine-5.4.3.2.1/bin/rubymine64.vmoptions -Xbootclasspath/a:/home/sony/Downloads/RubyMine-5.4.3.2.1/bin/../lib/boot.jar -Didea.paths.selector=RubyMine50 -Didea.platform.prefix=Ruby -Didea.no.jre.check=true -Djb.restart.code=88 com.intellij.idea.Main
sony      3900  2426  0 13:53 pts/1    00:00:00 grep --color=auto mine

I want to kill 3682.
'Simply kill 3682

Installing VIM editor on Ubuntu

1. $sudo apt-get install vim
2. Navigation when in VIM editor

Hit escape before executing any of the below:

  • :q to quit
  • :q! to quit without saving
  • :wq to write and quit
  • :qa to quit all
The bashrc file is located in the home folder.

Once the environment variable are set.

Source the .bashrc file and check whether environment variables are set or not.

(How to source : Go to your application folder and enter

source ~/.bashrc
The above sources your .bashrc file.)

For instance if you have set LDAP_HOST.

Then enter
   $echo $LDAP_HOST
The above command should return the value you applied to it.
e.g.  it would give. (in .bashrc you have, export LDAP_HOST=anyhost)
anyhost


Installing PostGresql

1. Use the sudo command

$ sudo apt-get install postgresql

2. Basic Server Settings

$ sudo -u postgres psql postgres

postgres=# \password postgres


--Enter password.(twice)


Type Cntrl D to exit postgres prompt.



3. $ sudo apt-get install postgresql-contrib

4. Installing postgresql-contrib

$ sudo apt-get install postgresql-contrib

5. If $ psql -l
     throws the error:
     psql: FATAL:  role "user_name" does not exist

It means you have to create a new user and assign it superuser access.

$ sudo -u postgres createuser user_name


Then you are asked if you want to make this as the superuser. Choose as required.

6. $ psql -l

Gives
 List of databases
        Name        |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges  
--------------------+----------+----------+-------------+-------------+-----------------------



 ......some text........
 
 
 7. check
psql --version 
And you should get something like this: 
psql (PostgreSQL) 9.1.9
contains support for command-line editing
 
Enjoy! 
 
8. If the user wants to check all PostGresSQL clusters. Enter command:
$ pg_lsclusters

You get something like this:

Version Cluster   Port Status Owner    Data directory                     Log file
9.1     main      5432 down   postgres /var/lib/postgresql/9.1/main       /var/log/postgresql/postgresql-9.1-main.log

 
 
 

Installing JetBrains

1. Download the file from http://www.jetbrains.com/ruby/download/

2. Unpack the contents using

tar xfz RubyMine-5.4.3.tar.gz

3. Go to the folder/bin.

Run

     ./rubymine.sh


4. Enjoy

Installing Ruby via RVM

1. $ rvm install ruby-1.9.2-p180
2. Add this to ~/.bashrc file
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

3. $ source ~/.rvm/scripts/rvm
4. $ type rvm | head -n 1
       should return a
       rvm is a function
5. $ rvm --default use ruby-1.9.2-p180

Thursday, October 10, 2013

Installing Ruby Version Manager on Ubuntu

1. Installing curl.

sudo apt-get install curl

2. Installing build-essentials

sudo apt-get install build-essential

3. Installing development libraries:

sudo apt-get install zlib1g-dev libreadline-dev libssl-dev libxml2-dev

4. Finally install RVM

$ bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)


5. And that's it.

Check the version:

rvm -v


You will get something like this:

rvm 1.23.4 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]




Installing Oracle JDK in Ubuntu

1. Installing Java.

Things you need to know.

a) JDK - Java Development Kit. (Usually contains one ore more JRE with it)
    JRE - Java Runtime Environment.

b) x86 is for a 32-bit OS, and x64 is for a 64-bit OS

1.1 Download the JDK from http://www.oracle.com/technetwork/java/javase/downloads/index.html.

1.2 Uncompress the file.

Command:

tar -xvf jdk-7u40-linux-x64.tar.gz

The above command installs the JDK in the current path.

1.3 Next task is to put the JDK in usr/lib path.

For this create a dir in /usr/lib/jvm

$ sudo mkdir -p /usr/lib/jvm

Change the directory of the current install

$ sudo mv ./jdk1.7.0_40 /usr/lib/jvm/jdk1.7.0_40


1.4 Run the following commands:
$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0_40/bin/java" 1
$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0_40/bin/javac" 1

The above commands set the priority for the current install as 1.


1.5 Alter the ownership and permissions of the executables by running the following commands.
$ sudo chmod a+x /usr/bin/java
$ sudo chmod a+x /usr/bin/javac 
$ sudo chmod a+x /usr/bin/javaws
$ sudo chown -R root:root /usr/lib/jvm/jdk1.7.0_40

Now check the java version
$java -version


You must get something like this:

sony@ubuntu:~/Downloads$ java -version
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)

For more instructions checkout --
http://www.oracle.com/technetwork/java/javase/