Friday, 31 October 2014

Download Naruto

So, the first release is out https://github.com/light94/naruto

The script will download the latest released naruto episode from narutospot.net. You must have beautifulsoup installed. just add the last seen episode number in naruto.txt and run the script.

Thursday, 30 October 2014

Added Utilities to ubuntu

This post will be a wiki for things that you can add to Ubuntu to make it more easier to use.

1)The good Open in Command Prompt utility from Windows.

Often , there are instances when you are searching for some file using your file manager(genearlly Nautilus) and then you need to do some operation on that file. Now imagine that the directory you are in has this path root/Downloads/Chrome/A1/B1/.... (as long as you can imagine). Now would you like to do so many cd commands or a single cd with a very long directory path. Here's something that is much better  than it.
You can add the open in terminal utility for linux using the following steps :

sudo apt-get install nautilus-open-terminal
Exit the terminal and now right click on any directory you are in. You will find an Open in Terminal  option there. 

Tuesday, 28 October 2014

MRO in Python

In Python, calling the super class' __init__ is optional.
However, if you override the __init__ of a class, you must explicitly call the parent class' __init__ with the current parameters.

This is done by :

super( nameofclass, self ).__init__() 



Python however supports Multiple Inheritance ,i.e a class can have more than one super class.

The MRO(Method Resolution Order - the order in which base classes are searched when looking for a method) is as follows .


1)Depth First Left to Right.
2)If any class is repeated in this search, all but the last occurrence of the class will be deleted.
3)Reject any class that has an inconsistent ordering of base classes.

Thursday, 23 October 2014

Cleaning the Python Terminal

This article is about the different methods that can be used to clear the python terminal

The first method is like this,

Ubuntu :
 import os
 os.system('clear')    


Windows:
import os
os.system('cls')




Second Method:

print chr(27) + "[2J" //python2

print(chr(27) + "[2J")  //python3

Note that this method is only for ANSI Terminals.

27 is the decimal representation of the escape key. So ESC[2J is recognized as ANSI clear command.

Third Method

just keep printing new lines like

print '\n' * 80

Wednesday, 22 October 2014

Getting scrapy to work on ubuntu

This post is for those who are trying to install scrapy on their ubuntu machines.

In order to install scrapy, the following components have to be installed
1)python 2.7
2)pip and setuptools
3)lxml
4)OpenSSl

When you install ubuntu, it also installs python 2.7.X,lxml and OpenSSL along with it (i've tested it atleast on ubuntu 12.04 to 14.04). In certain cases pip is not preinstalled , so you can install it like this:
sudo apt-get install python-pip

One thing that the docs do not talk about is installing the python development package. Trying to install scrapy leads to errors. You must install it prior to installing scrapy by:
sudo apt-get install python-dev


After this you just need to do a
 sudo pip install scrapy

One important point that I would like to mention is that people who connect to Internet by a proxy can still face some problem installing python packages.This problem has an answer here .
TL;DR append the E flag to sudo like sudo -E install scrapy. This makes use of the proxy settings to connect to the package library.