Monday, 4 August 2014

PYTHON BASICS

Dealing with Python basics



"""
This page covers max all the topics
conditional , loops , format string , string functions , lists
Dictionaries , files , directory , functions , definitions ,
modules , Exception handling
Remaining parts is covered in next post
"""
for y in xrange(1,10):
print y
print [1,2,3] * 3
a,b,c = 3,5,6
print a,b,c
odd = [1,3,5,7,9]
even = [2,4,6,8,10]
print odd+even
# string formatting
form = ("john","jell",3.14)
fs = "hello"
print "%s hai %s king %d" % (fs,form[1],form[2])
# String formatting with list
mylis = [1,2,3]
print "This is my list %s" % (mylis)
# Now we will go for basic string operations
one = "kri.sh.cdb.ry"
print "The length of the string %s" %(len(one))
print "The index of h %s" %(one.index("h"))
print "The count of letter r %s" %(one.count("r"))
print "In capslock %s and the Lowerlock %s" %(one.upper(),one.lower())
print "The sub string %s" %(one[0:5])
print "They start with = %s and ends with = %s" %(one.startswith("kris"),one.endswith("ry"))
print "The splitting %s" %(one.split("."))
# Now goes with operations like boolesn comparison etc..
name = "John"
age = 23
if age == 2 and name == "John":
   print "ok"
else:
   print "no ok"
i = 1
while (i<10):
print i
i=i+1
name,king = "krishcdbry","krishcdbry"
if name in[king]:
  print "yess"
if name is king:
   print "hey"
count = 1
while True:
print count
count += 1
if count > 5:
break
c=0
while True:
c += 1
if c%2==0:
continue
if c>5:
break
print c
# Function
def my_krish(n):
print "hello krish the number is %s" %(n)
def one_add(a,b):
    my_krish(a+b)
def one_main(name1,name2):
print "Hello dudes %s and %s" %(name1,name2)
one_main("krishcdbry","kingcdbry")
one_add(5,3)
# Going to objects and classes
class Krish:
car_name,car_cost,color = "Ferrari",7000000,"blue"
car_one = Krish()
car_one.car_name , car_one.car_cost,car_one.color = "Buggati",10000000,"Merun"
print Krish().color
print car_one.color
# Dictionaries
krishbook = {
     "krish":909090909,
   "Mohan": 964298874
}
# OR
krishbooks = {}
krishbooks["name"] = 9099900
krishbooks["one"] = 00123213123
for name, number in krishbooks.iteritems():
    print "Phone number of %s is %d" % (name, number)
del krishbook["krish"]
print krishbook
krishbooks.pop("one")
print krishbooks
# Dealing with files
""" Creating the file not exists """
fi = open("new.txt","wb")
fi.write("Hello this is krishcdbry's file buddy \n \n \n and This is just a cool python script");
fi.close()
""" Reading the file """
fi = open("new.txt","r+")
str = fi.read()
print " Reading the file = %s "%(str)
fi.tell() # Tells the position of the cursor
fi.seek(0,10) # Repositioning the cursor
fi.close() # closes the file
# Renaming the file name
# importing the OS module will helps to rename the files
import os # this imports the os module....!
os.rename("old_file_name.txt","new_name.txt")
# We can remove the file .. simply delete
os.remove("file_name")
# mkdir - for making new directory.....!
os.mkdir("new_dir")
# chdir - change the dir......!
os.chdir("dir_name")
# pwd current working directory...!
os.getcwd()
# rmdir - remove the directory
os.rmdir("dir_name")
# Exception handling
try:
   fh = open("jahe.txt","r+")
   fh.write("Hai this is another file....!")
except IOError:
  print "Their is no file found with name jahe.txt check it once buddy"
else:
  print "File found dude"
  # raise - we can raise Exception
  def function_name(level):
   if level<1:
   raise "Their is an error in this level"
   # the code below would not be executre if we raise this exception
read more...

Friday, 4 July 2014

GENERATING PUBLIC & PRIVATE KEY


GENERATING KEYS


In linux we can create public and private key

STEP 1 : Checking the ssh directory. So Just open the terminal and then type the below command

$ cd ~/.ssh
If the directory is present then you will get into it , now it is easy to create apair of public and private keys with just one command
$ ssh-keygen
$ Enter passphrase (empty for no passphrase): [Type a passphrase]
# Enter same passphrase again: [Type passphrase again]

Hence your public key and private keys are generated. Just check them by typing the following commmand.

$ ls -l

Now you will find the files like  id_rsa , id_rsa.pub , known_hosts.

id_rsa       : Private key
id_rsa.pub : Public key




Hence your keys successfully generated
read more...

TASK MANAGER IN LINUX


WE CAN FIND THE RUNNING PROCESS AND CAN KILL THEM BY FOLLOWING 2 STEPS



STEP 1 : Type "TOP" command in terminal.
$ sudo -s
$ [sudo] password for username : (type your password here)
$ top
It will give the list of processes running with process id , name , time , memory usage etc.



STEP 2 : Find the particular process and then it's respective id.Let us assume the process id as 12043 , then command goes like this
$ kill 12043

   By this we can kill/stop/abort a running process/hanged process.
read more...

NODE.JS - PART 2 (DOWNLOAD & INSTALL)

NODE.JS



First we need to download NODE.JS
Version : v0.10.29

Download Links:

Windows Installer (.msi)
  32-bit    Click here  
  64-bit    Click here

Windows Binary (.exe)
  32-bit    Click here  
  64-bit    Click here

Mac OS X Installer (.pkg)
  Universal  Click here

Mac OS X Binaries (.tar.gz)
  32-bit       Click here
  64-bit       Click here

Linux Binaries (.tar.gz)
  32-bit      Click here
  64-bit      Click here


IN LINUX & MAC


After downloading go to the folder containing the node's tar.gz file (Downloaded file)

Run these commands:

1.Extarct the tar.gz file

$ tar -xzf node-v0.10.29.tar.gz
2.Go to the extarcted folder

$ cd node-v0.10.29.

3.The configure and install

  $ ./configure
$ sudo make install


Successfully installed node in Linux

IN WINDOWS


Directly we can install the .exe file or .msi file , here the entire installation is in the similar way of installing a software.

After installtion we will get two things

1.Node.js Command prompt

 



2.Node.exe




Successfully installed node in your windows.









read more...
 
Copyright © 2014 krishcdbry • All Rights Reserved.
Distributed By Free Blogger Templates | Template Design by BTDesigner • Powered by Blogger
back to top