Thursday, 6 November 2014

Creating custom bash scripts

Often we across activities where the same set of actions need to be performed. These can be automated using bash scripts in Linux.

To make a bash script:
1) Begin the script with a shebang #!/bin/bash
2) type in the custom commands. Use $1, $2 etc. for passing in arguments to the script
3)Give it a name and save it in /bin   (Create a folder in home directory named bin)
4)Next , to make the file executable, type chmod +x <filename>

 Now you are ready to use the power of automation in linux. Have a look at https://github.com/light94/myShellScripts .

Wednesday, 5 November 2014

Hacking with Nautilius actions

I have been using Sublime Text for quite some time now and am an absolute fan of it. There is a very nice feature in it - open a folder . What it does is  that it gives you a list of all files in the folder in the package explorer pane. This makes it easy to select any file in the folder or editing, closing and reopening.


This is indeed very useful. But i thought of adding an alternative. Suppose, you are browsing through your projects and you stumble upon one of them and decide to work on it. It is painful(for me atleast) to open sublime text and then open in folder. What if there is an option present while browsing to open the folder in sublime ? Sounds cool.

So this link came to the rescue http://www.howtogeek.com/116807/how-to-easily-add-custom-right-click-options-to-ubuntus-file-manager/

Basically you need a tool called Nautilus Actions that you need to install by sudo apt-get install nautilus-actions. You then need to launch it and add a new action. Put a suitable name in Context Label (this is what will appear in the right click).  Then go to command tab and write subl in path and -a %F in parameters. subl is actually the command to launch sublime text from terminal . The -a argument adds folders to the current window and %F passes the name of the current dirctory to the command.


Then close nautilus and reopen it . Now when you right click on any folder, you will get the option to open it in sublime.

Tuesday, 4 November 2014

Onepiece Fans, Behold

After the script to download Naruto Shippuden episodes(https://github.com/light94/naruto), here(https://github.com/light94/onepiece) is the script to download Onepiece episodes. This is more customized than the previous.

Both websites offered almost the same structure and therefore the procedure is almost the same.

Facebook's Profile Picture Privacy Update

This is an update from an earlier post (http://justanotherlearner.blogspot.in/2014/08/facebook-bug-maybe-maybe-not.html) where I had misunderstood a feature of FB and pointed it out to be a bug.
Today, I came across the facebook privacy page (https://www.facebook.com/about/privacy/your-info#public-info)  where it is written that

"Your name, profile pictures, cover photos, gender, networks, username and User ID are treated just like information you choose to make public"



So, it is absolutely fine if you are able to download the profile pictures of others. However, FB still provides the option of keeping your profile picture private . There is certainly a discrepancy in information and it should be resolved.

Monday, 3 November 2014

Saving Passwords in Git

For git version >= 1.7.10
Entering the username and password everytime you do a git push is a waste of time. The following commands will save your credentials for a defined time period in memory.

To store your username and password, use the following commands

git config --global credential.helper cache

By default git stores password for 15 minutes. You can change this by

git config --global credential.helper 'cache --timeout=3600'

(If you want a timeout of 1 hour)

"Gotta" Catch'em All exceptions

So, I was recently doing a webscraping project. I had a database of people and I had to lookup and confirm their identity. Identity in the sense that they had either studied or taught in my college. The task can be done manually for a small set, but I had 7000 records!!

So I used xgoogle for this purpose. It is a Python Library for Google Search.
Now, after having completed the task, I can name a minimum 7 exceptions that can occur when you automate web lookups. They are :
SearchError (class in xgoogle that handles exceptions raised by google during searches)
HTTPError  (generally raised when there is some error in authentication, like trying to access a secured page of an organization, or when the url is http when it really should be https)
URLError (being a subclass of OSError, this error is related to system related problems like input/output . This includes error in fetching data from a url)
SocketError (Raised when there is some issue with the server eg. overload, throttle)
ValueError (Raised when the required datatype conversion is not permitted)
IncompleteRead (When the server closes the connection before the chunk of data has benn fully retireved.)
BadStatusLine (Raised when we request a webpage, and the server responds with a code that Python cannot understand)


Well this is not the complete list.

I had to automate the task in such a way  that I start the code before going to bed and I get it completed when I wake up. So, I decided to catch all :

try:
    my code
except KeyBoardInterrupt:
    raise
except:
 #handles all exceptions except KeyBoardInterrupt

This piece of code will ensure that unless you manually try to end your code, it will not stop.

Sunday, 2 November 2014

Testing your android app on your phone

This is something straight from the source(Google's android resources) and very important, How to test your android app on your phone?

Enable USB debugging on your device.
On most devices running Android 3.2 or older, you can find the option under Settings > Applications > Development.
On Android 4.0 and newer, it's in Settings > Developer options.
Note: On Android 4.2 and newer, Developer options is hidden by default. To make it available, go to Settings > About phone and tap Build number seven times. Return to the previous screen to find Developer options.