Posts

    Friday, 23 May 2014

    Say Thanks to birthday wishes on Facebook automatically

    One of the main reasons why people turn into computer geeks is because they are lazy :P Yesterday was my birthday. Again, thanks for all the wishes :) However I was lazy to manually thank each and every post on my Facebook wall. So I wrote a simple python script using Facebook graph API to say thanks to each of them. I didn't stop there. I am aware that many people think that thanking people manually is something that has always been very tiring. So I searched for all the simpler alternatives available to do this task and found that there was a Facebook app called "Say Thank You". It is simple and neat. However, it requires people to give access to post, like, get friend list..etc. Well, that is a mini privacy invasion :P. So it is a not a good alternative. Also in future Facebook might think that it is doing something against their policies..blah blah blah and bring it down. So not a permanent solution either.
    Hence I decided to rewrite the script I had written in python to javascript to make it accessible online. Well, here it is:

    http://alseambusher.github.io/say-thanks/

    For this you will need to get the access token. Getting access token is simple:

    • Go to developers.facebook.com.
    • Under Tools in the menu, go to Graph explorer.
    • Click on Get Access Token if access token isn't there already.

    Note that as this runs completely on the client side, users can safely use it without giving access to anybody (Although it requires you to give access token, it is not stored anywhere. See source ). And access tokens expire after sometime.


    Sunday, 27 April 2014

    Enable Tree View in Ubuntu 14.04

    I updated to ubuntu 14.04 recently. I was very disappointed when I came to know that the awesome "tree view" was not available in nautilus. I searched online to find if there was any way to get it back. Most suggested to switch to older version of nautilus, which is simply absurd. So I decided to figure out a way myself and I did.
    To switch to tree view first install dconf-editor.

    sudo apt-get install dconf-editor


    Then open dconf-editor. Go to org -> gnome -> nautilus -> list-view and check use-tree-view.

     Now your list view is tree view.

    Friday, 14 March 2014

    Unbuffer to the rescue

    Today I was running a c program which had to print lot of text on the terminal. However after some time it execution used to halt which seemed to be for no reason. This happens because whenever you write something to stdout, it stores it into a buffer till the process gets executed completely. To prevent buffering we can use unbuffer. This did the trick for me:

    unbuffer ./a.out 

    Whenever you redirect some command's output to a file, the output is first stored in buffer and then it s written to the file. Sometimes you may want to avoid this. Specially when the command is generating output continuously.

    unbuffer [command] > [file]

    In order to install it on debian or Ubuntu:

    sudo apt-get install unbuffer

    Saturday, 26 October 2013

    Performance modelling of a linux system using fork bomb


    Today I will be showing you a simple way to measure the memory allocation capacity of the system.

    Unlike in case of httpperf my method doesn't rely on the network based requests to load the system

    I will be loading the system with processes by running a shell script in each of the guest operating systems(If the system under test is a server virtualized system) The shell scripts can be controlled remotely using telnet.

    I would like to measure active memory, free memory, swap memory, inactive memory while loading the system with processes.

    The idea here is to get all the required performance metrics from /proc/meminfo while forking processes. For example at one particular instance on my system
    /proc/meminfo:



    MemTotal:        2945376 kB
    MemFree:          765960 kB
    Buffers:          144004 kB
    Cached:           993792 kB
    SwapCached:            0 kB
    Active:           979460 kB
    Inactive:         995496 kB
    Active(anon):     838076 kB
    Inactive(anon):   178496 kB
    Active(file):     141384 kB
    Inactive(file):   817000 kB
    Unevictable:          84 kB
    Mlocked:              84 kB
    SwapTotal:       6261756 kB
    SwapFree:        6261756 kB
    Dirty:               800 kB
    Writeback:             0 kB
    AnonPages:        837144 kB
    Mapped:           213612 kB
    Shmem:            179416 kB
    Slab:              91864 kB
    SReclaimable:      60272 kB
    SUnreclaim:        31592 kB
    KernelStack:        4000 kB
    PageTables:        39688 kB
    NFS_Unstable:          0 kB
    Bounce:                0 kB
    WritebackTmp:          0 kB
    CommitLimit:     7734444 kB
    Committed_AS:    4186924 kB
    VmallocTotal:   34359738367 kB
    VmallocUsed:      556904 kB
    VmallocChunk:   34359177692 kB
    HardwareCorrupted:     0 kB
    AnonHugePages:         0 kB
    HugePages_Total:       0
    HugePages_Free:        0
    HugePages_Rsvd:        0
    HugePages_Surp:        0
    Hugepagesize:       2048 kB
    DirectMap4k:       63488 kB
    DirectMap2M:     2942976 kB
    =======

    Also If we want to track any process, the folder /proc has details about each and every process running on the system.

    Regarding loading the system:

    There are two types of loads . Linear load  and Exponential load
    In linear load, one process forks another process and waits for it to exit. The spawned process forks another process and waits for its child to exit. This keeps going on and on till the system eventually fails. To load the system with linear load we ran the following shell script:

    #!/bin/bash
    $0 &
    wait

    "$0 &" will run the same script in the background and 'wait' will make the current process to wait till the spawned process returns.

    Similarly exponential load can be given by spawning 2 processes instead of one.
    #!/bin/bash
    $0 &
    $0 &
    wait

    Collecting data:
    The following code has to be embedded into the above script
    # <epoch time> <PID> <Memory free> <swap free> <active memory> <inactive memory>

    string=`date +%s`" "$$
    i=`cat /proc/meminfo| grep "MemFree:"`
    string=$string" "`expr "$i" : ".* \(.*\) kB"`
    i=`cat /proc/meminfo| grep "SwapFree:"`
    string=$string" "`expr "$i" : ".* \(.*\) kB"`
    i=`cat /proc/meminfo| grep "Active:"`
    string=$string" "`expr "$i" : ".* \(.*\) kB"`
    i=`cat /proc/meminfo| grep "Inactive:"`
    string=$string" "`expr "$i" : ".* \(.*\) kB"`
    echo $string>>log
    Sample output for linear load:
    Sample output for exponential load:

    Error removing file: Directory not empty

    Something really weird happened today. I transferred some data to my external hard disk and for some reason I unplugged it from my comp without doing 'safely remove drive' (reason being I was lazy :P). Then after sometime I put it back on my laptop and tried removing the directory called Main_Game which I had created earlier. It said 'Error while deleting. Error removing file: Directory not empty'.

    Then i tried doing that from terminal using 'rm -rf Main_Game'. Again it didn't work. It said rm: cannot remove 'Main_Game': Directory not empty


    Then I thought there might be some process using that folder. So I restarted and tried again. It didn't work :(

    Then I thought there might be some error in the filesystem. So I did force fsck.

    $ sudo touch /forcefsck
    $ sudo reboot

    It successfully completed fsck. However the problem wasnt fixed

    Then I did something which I should've tried long back and it worked!!

    I simply deleted the folder (not force delete). The folder Main_Game was moved to recycle bin. I just deleted from there.

    I dunno how this worked though :P

    Saturday, 7 September 2013

    Automatic log manager for Game of Thrones series.

    I watch a lot of anime. When I started watching One Piece which had 500+ episodes, it was very hard for me to keep track of how many episodes I have seen already. So I used to keep a log file which always had the next episode's number and I used to manually update it whenever I watch an episode.

    That was a good idea but not good enough :P. At least for awesome people like me doing work manually is too mainstream xD.
    If you do all the work what is your computer there for???
    So I wrote a script which automatically manages the log. And next time when I run the script it will continue from the place I stopped last time \m/. Now I am planning to start Game of Thrones TV series. People tell I'll like it because I am a big fan of Age of Empires and I love wars :D.

    So now what I am planning to do is to automate viewing it just like I did for One piece. In the version of Game of Thrones which I have, each episode name has SxxExx in it. For example S02E09 is there in the file name of episode 9 in season 2. So using this I can iterate over series and inside that i can iterate over episodes.

    Setup

    Download the gist from here or copy it from here:

    Step1

    Place the script in the base folder which has folders of all the series. Make it executable:
    $ chmod +x script.sh

    Step2

    create a file called "log" in the same folder. The log file contains current series number and episode number. For example if you are watching third episode of season 1, put 1:3 in that file and save it.

    Running:

    Just go that folder in terminal and do this:
    $ ./script.sh

    Now just enter the  number of episodes you want to watch in a stretch and enjoy!

    Monday, 20 May 2013

    Customizing linux terminal with powerline (powerline-shell)

    Borded of how your terminal looks?
    In the past I used to edit the bash superglobal $PS1 to make it look a littile better.
    I found this awesome thing called powerline-shell on github which makes your terminal look so awesome. Not only it makes your terminal look beautiful it also helps us to visualize many things easily. Like errors, git stuff..etc
    I took some time and modified it a little. Here is mine:

    Download

    How to get it?


    1.  Download powerline-bash.py from the link and place it in the home folder.
    2. Make it executable

      chmod +x ~/powerline-bash.py
    3. Then add the following lines to the file ~/.bashrc:
      function _update_ps1() {    export PS1="$(~/powerline-bash.py $?) " } export PROMPT_COMMAND="_update_ps1"
    4. Now patch the font. Download anonymous Pro-Powerline.ttf and open it to install it
    5. You are done!!! Now just open the terminal.


    NOTE: If it doesn't work properly and prints some garbage elements then u have to patch the font you are using for your terminal from here

    Saturday, 18 May 2013

    Jarvis, at your sevice


    Hello everyone! Its been a long time since I blogged. Today I will show you how to use 'Jarvis' which is an open source software which can be used to control your Linux system using your hand motion, gestures which was made as my Human Computer Interaction project. This is mainly an image processing based project developed using python.



    Things u can do using Jarvis:


    1. The first thing you can do using Jarvis is control your mouse. You just need a colored object (preferably has color different from its background). So you can do things like draw in air!
    2. The second thing is that you can assign any gesture which is a combination of
      Left->Right, Right->Left, Top->Bottom, Bottom->Top to any command. So using this you can literally perform anything!!! The following are the things you can do by default:

    • Maximize/Minimize/Close current window
    • Go next and forward in PPT presentation
    • Page up and Page down
    • Switch window (Alt+tab)
    • Take screenshot
    • Shutdown/Suspend system
    • Mute and unmute
    • Open Calculator, File manager, Gedit


    You can practically add anything else also. All you need to know is the command which does that and the equivalent of the gesture which you want to assign in the combination of Left->Right, Right->Left, Top->Bottom, Bottom->Top.

    Getting dependencies:

    Ubuntu:
    $ sudo apt-get install python-opencv xdotool
    Fedora:
    $ sudo yum install python-opencv xdotool

    Installation:

    $ git clone https://github.com/alseambusher/jarvis.git
    $ cd jarvis
    $ ./install

    Now you need to set the screen resolution of your screen. If your screen resolution is 1366x768 then skip this step.
    $ gedit ~/.jarvis/config.py
    change the value of variable RESOLUTION corresponding to your screen resolution.

    Running:

    Now simply open Jarvis from your Applications menu
    OR
    Do this:
    $ cd ~/.jarvis
    $ python main.py
    Now click on Start Jarvis 

    Add new gesture:

    1. Go to settings from the File menu


    2. Click on Add gesture from the File menu of settings


    3. Suppose say that you want to add a gesture which opens terminal.
    Say the gesture you wish to give is (Left to Right)->(Right to Left)->(Top to Bottom)->(Bottom to Top)
    The command corresponding to open gnome terminal is 'gnome-terminal'

    4. Fill the details and save it.


    You are done!!!

    Editing and deleting gestures are simple :P

    How to use?

    We need two different colored objects which are required to run. One the tracker and the other one is the flag!

    1. If the flag is not exposed then the gesture is disabled and Jarvis works as a mouse controller.
    2. When both tracker and flag are exposed the gesture begins. Perform the gesture using the tracker. Once the gesture is complete hide the flag. Jarvis then processes and analyses the gesture performed and checks for any matches from the existing database. If there is a match then it executes it!.

    Customizing Tracker and Flag color:

    By default the tracker is yellow color and flag is blue color.
    You can change it by editing the config.py file

    $ gedit ~/.jarvis/config.py

    Change the min and max values of TRACKER_COLOR and GESTURE_COLOR corresponding to the HSV values of the color intended

    By default these are the values:
    TRACKER_COLOR={'MIN':[20,100,100],'MAX':[30,255,255]}
    GESTURE_COLOR={'MIN': [108.0, 100, 10],'MAX': [118.0, 255, 255]}

    Thank you. Dont forget to contribute to this open source project as there is a lot of scope for improvements. :)

    Fork the project from here: https://github.com/alseambusher/jarvis

    Thursday, 4 April 2013

    Open with script in Gnome/Ubuntu

    I always liked the feature open with script which was there in old ubuntu. I have no clue why they removed it. However as always in Linux there is always a way to do anything! Today I will show you a simple way( complex than before though ) to do it. Using this I was able to install Picasa Photo Viewer, Logism, yEd, MS Office..etc on my Ubuntu \m/

    Step 1: Find MimeType of the target file (the file you want to open). You can find it in file properties


























    Step2: Download this gist. And make it executable:

    $ chmod +x open_with_script.sh

    Step3: Then run the script and enter necessary details. For example I was trying to install yEd, an awesome Software Engineering Drawing tool. This is what I did:
    NOTE that if the command is <command> <file name> enter as <command> %U





















    Step4: This step is optional. This is to set font to the script. If you don't wanna do it, skip it. Open application called "Main Menu" or alacarte which comes by default in ubuntu. Then search for the script you just added and then set the font.

























    Step5: Now just set the file to open with the script by default if necessary using file properties.


























    Now you can simply open the file using yEd by default. So you are done!!! 

    Saturday, 16 March 2013

    Installing Turbo Assembler (TASM), Turbo Debugger (TD) on Ubuntu

    Step 1
    First we will install an windows emulator called dosbox.
    sudo apt-get install dosbox

    Step2

    Download the packages for Turbo Assembler(tasm) Turbo Debugger(td)Create a directory for tasm in your home directory and extract files into that directory.If you are unable to extract type this in your terminal and try again
    sudo apt-get install unrar

    Step3

    download this sample .asm file. Place the file in the tasm directory.

    NOTE:  You can use your own asm file instead

    Step4

    Open dosbox( generally found in games sublist ). Now you have to mount the virtual c drive.
    mount c /home/<username> eg: /home/alse

    Step5

    Now go to your TASM directory



    Now test the test3.asm which you downloaded