Posts

Showing posts from 2016

Project Holy_Python_Grail_Quest - To insert multiple values in multiple keys of an Ordered Dictionary

So, I have been progressing on my Pythonic Quest. On this quest, I have learnt and found about many libraries and functions. Also, I have come across some interesting problems like the one mentioned in the title. It serves as a temporary stop gap in my application until I implement sql or something better in my application. So, my requirement is an ordered dictionary having multiple keys with multiple values. This ordered dictionary acts an SQL table having primary key. I hope you get an idea about what I'm talking about. So, given below is the way I implemented it:  from collections import OrderedDict  #First initialize OrderedDict using its constructor  a = OrderedDict({'name':['James','Bond'], 'id':[101,102']}) #Define keys key1 = "name" a.setdefault(key1,[]) a[key1].append( 'Max') key2 = "id" a.setdefault(key2,[]) a[key2].append(103) Output will be: OrderedDict ( [ ( 'id', [101,

Project Holy_Python_Grail_Quest - Argparse

In this post, I'll be sharing my notes on Argparse module on python. I've come across argparse module while working on my project. After googling, I've found this great tutorial at official python website:  https://docs.python.org/2/howto/argparse.html . If you go through this, you'll get a very good idea about argparse and its usage. I'm just posting this as a summarized version of what I've understood from the tutorial. Anyone can go through this for quick reference. Introducing Positional Arguments :  import argparse parser = argparse . ArgumentParser () parser . add_argument ( "square" , help = "display a square of a given number" , type = int ) args = parser . parse_args () print args . square ** 2 add_argument - To specify command line arguments the program is willing to accept parse_args() - returns some data from the options specified help - gives an idea about what the argument does a

Project pyCountVids - Python Script To Count Total Videos in a Directory

So, I've started working on my long awaited project by implementing it in small increments. First, I've decided to write a python script that counts total videos in a directory and its sub-directory. #!/usr/bin/env python2 import os import sys rootDir = sys.argv[1] totalVideoCounter = 0 videoExtension = [".3g2", ".3gp", ".asf", ".asx", ".avi", ".flv", \                         ".m2ts", ".mkv", ".mov", ".mp4", ".mpg", ".mpeg", \                         ".rm", ".swf", ".vob", ".wmv", "m4v"] for dirPath, subdirList, fileList in os.walk(rootDir,topdown=False):     dirName = dirPath.split(os.path.sep)[-1]     videoCounter = 0         for fname in fileList:       if fname.endswith(tuple(videoExtension)):             videoCounter +=1             totalVideoCounter +=1     if (videoCounter > 0)

Project Dumbledore - How to download YouTube Playlist on your system

Image
As, I was going through some great lectures available on YouTube, I thought of saving them all in a playlist and then downloading them all for offline viewing on my system. After googling for few minutes, I found this great command line program youtube-dl  to achieve this. It ticks all the right boxes - simple, open source, platform independent and python based. To install this on Ubuntu based systems, run the following command on your terminal: sudo apt-get install youtube-dl To download YouTube playlist, run the following command: youtube-dl -ctik   https://www.youtube.com/playlist?list=XXXXXX It has many other great features, be sure to explore them all. Though, I have found a problem that it downloads video and audio files separately and then combines them together in a single file leaving two extra files after each download which needs to be removed after the download is complete. I haven't looked into it to find the issue. If I find the solution, I will updat

Project Valentino - How to download Permanent Room Roommates Season 2 Episode 1 from TVFplay.com

Image
So, I was down with stomach bug and decided to spend my Valentine's Day morning watching the new episode of Permanent Roommates Season 2 on their website TVFplay.com . But sadly, they were not using Youtube Player embedded in their site (as they repeatedly proclaimed in their last videos about doing so) and my net speed is not that much to view it smoothly without any buffering or interruptions. So, I decided to download the video on my desktop for my viewing pleasure later on. First, I decided to inspect their webpage and found out that they were using brightcove player (and also that they are using angularjs. Thumbs up for that). So, after googling a bit, I found out that on following the given below steps, one can easily download videos off a brightcove player: 1. Open Google chrome and in address bar, enter chrome://plugins/ 2. Disable the Adobe Flash Player Plugin. 3.  Go to TVFPlay.com. Before starting the episode, click on your right mouse button. Go to Netwo

Project CleanSlate - Bash Script to Install Your Favorite Applications on Xubuntu

Image
So, I kinda crashed my HDD last weekend. But thankfully, I have had made a backup of all important data. But sadly, I haven't yet find a way to make a backup copy of my customized Linux OS with all my favorite and necessary apps and settings. But I got a brief flashback of the horror that I used to go through earlier while installing Ubuntu as shown below: But thanks to Xubuntu, I don't have to face such horrors again. Even though, my habit of experimenting and to resurrect the buried ghost of Windows led me to this: Thankfully, my sanity returned and I decided to install only Xubuntu on my system. Also, I decided to follow the principle of automating and wrote a bash script to install my following favorite (and must have) apps on my newly installed system: vim - Text Editor for all my programming tasks and scripting gedit - Another Text Editor Docky - Dock Application vlc - Media Player smplayer - Another Media Player Deluge - BitTorrent Client Clem

Project Wild Penguin - Installing Node.js on Xubuntu 15.04

Image
In this post, I have going to share the simplest way to install Node.js on your Linux system, specifically, Ubuntu and its other flavors. The server side component of the MEAN stack - node.js can be installed on your Linux server by following the below steps: 1. Go to  https://nodejs.org/en/download/  and download the Linux binaries based on your system architecture (32 or 64 bit). I've downloaded the 64 bit version. 2. Open the terminal and type in the following command:           sudo tar -C /usr/local --strip-components 1 -xzvf node-v5.5.0-linux-x64.tar.gz  3. Both node and npm should now be installed in "/usr/local/bin" and check this by typing:               ls -l /usr/local/bin/node       ls -l /usr/local/bin/npm Alternatively, you can check the version of node installed by typing:     node -v Thanks to the Coding Samaritans out there. My online nightmare is what will happen to me when I will encounter the following scenario: Scary. Isn't

Project Wild Penguin: The Environment (To Find version of Ubuntu or desktop environment you are running)

Image
I have had an on and off relationship with the Wild Penguin, the Linux. The reason for this was my lack of trust on the stability of the Linux Desktop Environments that I tried. The main issues started when Ubuntu made the switch to Unity which caused my laptop to overheat due to AMD drivers issue. It also kept sending my old desktop into dark space exploration by breaking its GUI on every second boot. This complicated relationship turned into a stable partnership when I came across xfce-based Ubuntu flavor called Xubuntu.  I have been using it for more than a year on both my lappy and desktop. And after using it for so long, it has become my favorite OS. It has helped me make the complete switch from Windows to Linux. Now all my devices, my tab, phone, desktop and laptop all run on Linux based operating system. It is a important partner in my Odyssey to become a better computer scientist and engineer. So, while I was trying to brush up my Linux command line skills, I got a questi

Project Wild Penguin - The Master Code

Image
So, I was lost in the labyrinth of the Programming Heaven for a while. There is so much to learn, so many shiny new technologies and concepts to learn that I end up being this guy: That's right the Master of Chaos. So I'm trying to bring some method to my madness. I have decided to use the following Master Code to get my fundamentals strong and basics right. The Master Code: 1. Learn a relevant programming language (or any language that you're interested in or in love with. In my case, that would be python) 2. Practice and do some interesting stuff in it. 3. Learn Data Structures and Algorithms and practice through it. 4. Keep making connections with other components like networking, operating system and database concepts. 5. Most important of all, keep experimenting and updating your self with new technologies as well but always in moderation. And hopefully, I will follow this code and in the end be more like this: Ciao.