Friday, March 20, 2015

Knowing a Language and ability to Code.

Recalling all the placement discussions we all had, one general question: Rate yourself in the particular language. Recalling all the college placement interviews, I was asked, "Rate yourself in C++"

So my first question was always, what do you mean by rating, is it knowing the language or the ability to code. Mostly the interviewer gave me a diplomatic answer. I was not convinced myself as well. This was one quest I was since I was in college. Thanks to my colleagues and friends, I think, I can arrive at a specific answer.

Coding is an art, the way we use language constructs to minimize the efforts we are putting in. For example:

Problem Statement:
Given an array, sort it such that even numbers are in descending order and odd are in ascending.

Assuming we are given a function sort(array.begin(), array.end()), using conventional programming methods we won't be able to use this function. So If I am coding using C++, following will be the approach:

class modifiedInt{
public:
  int element;
  bool operator < (modifiedInt) const{
    if (modifiedInt.element & 1)  //Odd
      if (modifiedInt.element < element)
         return 1;
      else 
         return 0;
     else //even
      if (modifiedInt.element > element)
         return 1;
      else 
         return 0;

//Similarly operator> operator== operator< can be defined

};

After the above definition, we can directly use sort function provided to us, Here Using language constructs, the coding is simplified.

This is a very simple example, where we are using language constructs to simplify our logic and increasing code portability, usability and scalability.

The knowledge of a language provides us a tool we can use in coding. They are the basic things which help an art become easy. Given an algorithm, its not so difficult to code. Knowing the language constructs only help in achieving our end goal.

So Next time, if we are asked how do you rate yourself in C++. Lets hope we would rate myself more comprehensibly.


Feedbacks/Comments are most welcome.

Friday, October 3, 2014

Khoj - The multi-platform search engine

Problem Statement: Most of the developer use more than one operating system. Be it different flavors of Linux or Windows or Mac. This generation is lazy, we want to finish things as soon as possible! So we use search. No need to remember location of files, just enter a string and let OS worry and fetch it for us. Here the problem arises. Suppose I have a 1 TB HDD. I insert into one OS, search for a file, let it index for 30-45 minutes then search. I lend my HDD to some friend of mine, then they do the same exercise or I plug the same to another OS of mine.

Now, searching is the most basic thing. I have a smartphone and want to know if a file is present in my PC or not, why wait to go home?

Solution: A generic framework with all device compatibility, Using a database, which can be easily ported, and provide a uniform searching experience with minimum latency across all devices. 


We already have very efficient searching tools, why another?

  1. Web based searching are quiet different from desktop searches, web based searches gives priority to "whole words" instead of sub-strings. For example, the string "example", "ample" would be treated differently in a simple web-search as there are many relevant results. As there are relatively fewer number of files in desktop, results with string "ample" will also return results with "example".
  2. Different platforms have different tools for searching, which index locally, not portable to other systems. A shared DB will not only help solve this problem but also provide homogeneous platform for all platforms.
What languages will be used to develop?
As this is being developed with "generic" in mind, currently we are restricting our back-end to python. We are yet to decide on front-end.

Github Link: Khoj

Monday, March 18, 2013

Arithmetic Practice tool

Placement season is always on and people just keep solving questions and all, but OOPS!! at some piece of time you run out of arithmetic questions or you are too lazy to do so (the latter case happens to me most of the times), I came up with a solution, why not develop a simple program to ease all worries.

As a result of which I developed a simple application: Arithmetic Practice tool. This application asks the user which one he wants to practice (Addition/ Subtraction/ Multiplication/ Division or a randomly chosen operation). The user also has the flexibility to choose the range of numbers he wanna work upon, in this version, I have just included integer operations.

NOTE: For all division problems, you need to give an answer upto three decimal places. (ie an accuracy of 0.001 is required)

The application can be downloaded from here.
Or you can simply copy paste this link http://goo.gl/Tn9e0 in your browser.

Advantages, once you are all set for a particular set of problems, particularly Data Interpretation in this case, you can really try this application. The source code is also provided with this, so that you can also try some changes. The app can particularly help students aspiring for examinations demanding speedy calculations.

The application is licensed under GNU GPL v3+ 

Saturday, December 8, 2012

Sharing a folder Fedora 16 via FTP

Today I was trying to share a very large folder ftp. One Idea was to copy the complete folder to /var/ftp, but this is a bad way when Linux kernel supports mounting a directory from multiple locations.

1. Installing FTP server
    On fedora its as simple as yum install vsftpd
2. Start the service
    service vsftpd start
3. Adding this to startup
    chkconfig vsftpd on
4. Mounting the directory using
    mount --bind [directory to mount] [directory in which it would be mounted]
As I was trying to mount sdb drives to the specified folders, I was unable to open them via ftp although they were working fine using nautilus. I googled then I found a solution of setting SELinux to Permissive mode using setenforce 0

Since mounting operation needs to be done after every boot, I made a simple text file:

mount --bind /media/H/ /var/ftp/Shared
mount --bind /media/I/ /var/ftp/Another

setenforce 0
A snapshot of the same
Deep inside directory tree

Tuesday, October 23, 2012

Core Dump Resolved

This is a follow up blog to my previous one: Core Dump

As a part of the design, I was passing an element of a second degree vector, for instance, the vector was:

vector < vector < pathDetails > > someName;
I was passing someName[ i ] to function createLightTree. As described in my previous blog, It was repeatedly giving core dumps (std::bad_alloc), so I decided to use a temporary vector for passing values to the function.

So I used another vector

vector < pathDetails > temp
and passed to my function createLightTree, and it worked!!!.

I am still wondering why this happened, as in some of my recent codes, I passed vectors of size 1 GB and it was working fine, the only difference being my distro (last time I used Ububtu and I use Fedora now), but I guess gcc us universally constant with respect to its standards.

Another possible reason could be, the "pass by value concept" the compiler might be copying all of 3-D object to pass on to the designated function.

And at the same time, her ek friend jaroori hota hai, special thanks to my friends who helped me get out of this.

Monday, October 22, 2012

Core Dump

Earlier I had encountered many runtime errors in my programs like Segmentation Fault, stack crashing etc. Segmentation fault was a bit difficuilt to track till I learnt the debugger.

Recently while working with files IO in my simulation of a network I encountered core dump. Later I learnt that the directory path given by me was incorrect. As a next step of simulation the same problem cropped up, I called a function with function signature:

pathDetails createLightTree ( string id, vector <pathDetails> trees, int iteration );
and definition:
{
    std::cout<<"Test line"<<endl;
    pathDetails sample;
    return sample;
}


pathDetails is a structure having related integer constraints required to simulate a Multicast Optical Network

It has been frustrating as I am not able to execute even the first dummy line. The error message is:

terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
Aborted (core dumped) 

Here is the screenshot of the same:

Saturday, March 31, 2012

topcoder

In a recently installed Fedora 16 of my friend, topcoder arena was not able to start. One possible solution was installation of Oracle Java because Iced Tea Java dosen't have proxy support. Even after installation, javaws was unable to start. One possible solution could be the $PATH variable. I checked, it was like:

[saurabharaiyer@localhost ~]$ echo $PATH
/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/saurabharaiyer/.local/bin:/home/saurabharaiyer/bin:
[saurabharaiyer@localhost ~]$

There was no javaws in the above folders, the default location of javaws is
  
/usr/java/jdk1.7.0_03/jre/bin

So we just need to change the path variable.

PATH=$PATH:/usr/java/jdk1.7.0_03/jre/bin

one reference I later found: http://roshansingh.in/blog/2009/11/11/running-topcoder-applet-behind-proxy/

Wednesday, July 27, 2011

console age calculator

Its long since I blogged, thanks to some unfinished network maintenance stuff. This time its a console age-calculator, the git version calculates the month and year and date difference given by the user, still its a good time pass and strong back-end for another Qt application :P.




source code:
github, wish me luck :)

to run the code, in terminal type:
$ g++ age.cpp -o age
$ ./age

Wednesday, July 13, 2011

a day in my school, spreading message of open-ness

DAV Gandhi Nagar AISSE-2007 get-together, June 30 2011: Some things were to be done, seeking required privileges to give juniors a talk on Open Source. Principal S K Sinha, was welcoming, gave me the liberty of choosing, tum jab aoge, tab kara denge.

Tuesday July 5, 2011: It was already late when I woke up, and slides unprepared, but the talk had to be given, typical college lazy bug, some points were chalked and Images downloaded, all set to school!

OK fine, principal sir was leaving, had to talk to VP Mr B K Singh
  • There was no such auditorium to support the strength of classes I requested [class IX and X], one hall which school had was turned into classroom(s).
  • The talk could only be allowed if there is no test the following day, wtf..., I had not talked beforehand for this kindaa .... .

Frustrating, but finally permitted! phew, gates to OPEN SOURCE were OPEN, 2 periods were alloted, 45 minutes each, and now the problem was, I had to give talks to two different batches, all class X, no IX. I had to compromise with my talk duration.

Anyways, I was more than satisfied for it, at least the message could be spread to some, something which should have been known to them (by then). In a small places like Ranchi, we seldom come in touch with any such technologies (except core i processors, new propitiatory OSs, thanks to ads). Some kind of myth supporting, doing this is good, this is not good etc, etc. Talking about me, Open Source and Free Softwares was with me for the first time in 2009 sometime after I joined the college.
in our school library

The session was titled
Introduction to OPEN SOURCE and FREE Softwares, there I was assisted by Chinta. It all went well. Happy-happy ending!! [:)] was a bit doubtful how well my message would have penetrated those guys, I was in library all the time, library mam ( I forgot her name :P ) introduced me a student called Prakhar Prasad. Coming beyond my expectations, he proved to be a real FOSS guy, exploring since past three years, his area of interest is Network Security. FINALLY there was some feeling of achievement. His softpedia profile.

Comment for slides, they would be mailed directly to you.

While discussing installing linux based OSs in school's computers, I came across some inevitable problems coming out of CBSE hypocrisy. Norms are there to work on linux boxes but the copies with #include<iostream.h> are considered right. [my gcc compiler never accepted this].

Tuesday, July 12, 2011

Back-end Database to slamBook

Some changes:

in the *.pro file it needed to be included
QT += sql    // taking care of case

although the backingdb.cpp file is not functioning properly as expected, it places 21 out of 23 parameters in place [which may still be considered as a failure]. Even after cross-checking the syntax several times and writing from scratch, the  real bug could not be figured out, soon the code would be split into database tables in a 'tab specific' manner hence reducing number of parameters passed per function.


The database, compared to previous HTML outputs, gives an upper hand in data management.

Here are the screen shots of all tabs:





I would be rude if I don't mention Prakhar Prasad in this blog. Also acknowledging all previous names mentioned under label slamBook.

[github link to this commit]

Thursday, July 7, 2011

Documentation to slamBook

some Qt stuff:

Signals and slots are used for communication between objects.I have implemented it using 

QObject::connect( sourceObj , SIGNAL(typeOfSignalGenerated()) , destinationObj, SLOT(actionToBeInitiatedForSignal()) );

Suppose in Image tab, I paste a URI and click attach button(or press Alt+t) a signal 'click()' is generated by this->ui->pushButton_7, ui being the present object, then it requires this to be acted upon by a SLOT [or a function, written specifically for acting to a SIGNAL] called imageView(). 
[lines 78,79 in mainwindow.cpp].

About the code: xml file is automatically generated WYSIWYG feature of Qtcreater coming handy saving a lot of time in User Interface design.

slots:

void Accept() : this SLOT (or function) reads the values from UI and push to an HTML file. Those values are of QString [using *.toStdString()] type, and needs to be converted to std::string, as no operator<< is defined in order to complete file insertions.

void imageView() : it fetches the image from imageURI provided ans shows it in QGraphicsView.

To compile and view the application, you need to:

pull the code from git@github.com:saurabhsar/slamBook.git
or URI


$ qmake slamBook.pro
$ make

and Run the output file:

$./slamBook

Happy cute(Qt)-ing. 

Slam Book v0.02

Compared to last version, this has the following changes
  • a tab exclusively to view image has been added [1].
  • now we can switch through textEdit by pressing tab
  • some changes in HTML output.
  • changes have been made to ambiguous options like 'About', 'You are crazy about', 'Hobbies and interests' to make it more specific [2].
  • one line informal description to every textEdit(s).
  • the dateTimeEdit is replaced by dateEdit for filling Date Of Birth


Hope you enjoy this!

Codes on github: Direct link to this commit

Test


[1] Tirtha for his hints in making imageViewer work [blog].
[2] Rolie, Srishti and Aishwarya, for their feedback on the same.

Tuesday, July 5, 2011

Slam Book

This is my second project using Qt. Compared to my previous Numerology Calculator, it is a much organized effort having pretty specific files. The whole code was written using Qtcreater as an IDE, Its effectiveness and efficiency made it possible to push out the v0.01 in less than 24 hours form the moment it started.
a screen shot

This application only performs write operations, no pre-existing files generated could be edited or viewed in it. The output is stored as a plain HTML file.

Source Codes
git
Output files of this app
Distributed under GNU GPLv3+


PS: I should mention my friends, who inspired me for this.

Monday, June 27, 2011

My first Qt app

So with sparse matrix on stands, and summer haunting, something had to be done. Qt haunted my empty brain this time. Simple thought of 'MY' app made me Qt aficionado. Now the thing was, WHAT. I have always been fascinated by numerology, so the track was set.

About the code: a SLOT had to be written, taking input from QLineEdit, and calculating the numerology subsequently displaying it to QLabel via QSpinBox.

The first version of looked something like this:

With a QSpinBox showing the numerological equivalent of QString ( or user Input ).


It had some bugs, specially with QSpinBox, The value can be changed and was not right to use it as an output widget, so here came my second version:

Its cool, QLabel replacing QSpinBox, responding to shortcuts like Alt+C, Alt+Q


would be uploading the codes soon...

Apart from it, I have added restrictions to window size to avoid defacing of the app on maximizing.


Codes
License: GNU GPLv3+ view

PS: Suggest me some more numerological stuffs, to make this a real cool app, looking forwar

Saturday, June 25, 2011

sparse.cpp,

This might be my last post related to sparse.cpp, failing to code as per my expectations and goals this became an idea not so longlived. I would be uploading the working code soon, fixing some errors, or curtailing the erroneous codes.

This blog post may mark an end of coding phase, not the end on sparse.cpp. Any one looking forward to work with me on this, is most welcome :). Please get me on any of the contacts listed below or simply leave a comment, I'll definitely get to you.


twitter
irc: saurabharaiyer
(#nitdgplug on freenode)

Saturday, June 18, 2011

When Network icon is not coming in notification area

No problem, again open the terminal, and type the following commands

  • sudo service NetworkManager start
  • sudo chkconfig NetworkManager on
source:       nitdgplug [google group]
thanks to:   Shreyankg and Arjun Basu


Thursday, June 16, 2011

Adding more flexibility, to #include "sparse.cpp"

This is my third blog post regarding #include "sparse.cpp". I have tried to embed more user friendliness this time. display() function is still giving segfaults, and the definitions of retrieve( int, int ) and remove ( int, int ) are not included in the source.

Complete source code(s)

One major change this time: The code is split into header and definition files.

sparse.h:

 /* 
  *  This program is a part of an attempt to implement Sparse
  *  Matrix in C(plus)(plus)
  *
  *  Copyright 2011 Saurabh Araiyer <sizzsa(at)gmail(dot)com>
  *
  *  Licenced under GNU GPL v3+
  *
  *  Downloaded From http://goo.gl/WNrQZ
  */
 

#include <iostream>
#include <vector>
#include "llnode.cpp"

using std::vector;
using std::cout;
using std::cin;   
/*
 * std::cin and cin::cout to be removed in later phase(s) 
 * included for verbose input
 */

#ifndef SPARSE_H
#define SPARSE_H

template <class T>
class sparse
{
public:
    llnode <T> *root;
    sparse(char cVerbose = NULL);
    sparse(vector <T> , vector <int> , vector <int> );
    ~sparse();
    int insert(T , int, int);
    void dispaly();
    void vertical(int);
    void horizontal(int);
    T   retrieve(int, int);         // Input is Array indeces
    int remove  (int, int);         //Synonymous to delete, input is array indeces

private:
    int m,n;
    llnode <T> *temp;
    int maxval(vector<int>);
    int push(T , int, int);
    int index_return(int, llnode <T>*);
    int incase(int, llnode <T>*, int, int);
};

#endif // SPARSE_H

Monday, June 13, 2011

#include "sparse.cpp" insertion function

This time its happy news for me, all segmentation faults from the insertion function has been resolved, in this version of my code, I have removed the display function, an addition in the form of retrieve function would be done soon, so that values could be fetched from the sparse <type> object.

Click for Source code
All source codes and screenshots

Tuesday, June 7, 2011

#include "sparse.cpp"

I was thinking about 2-D arrays and memory, there it stroke me Sparse Matrix, a relatively efficient way to do so. Then why not develop it, there it started rolling:


Source Code
Mapping of nodes, for easy understandibility

Things done to create a node:
            __________________
            |                |           |
            |                |           |
            |        1      |     2    |
            |                |           |
            |_________|______|
            |         3     |     4    |
            |_________|______|

1. template <class T>class node :: <T> data. //Template
2. template <class T>class node :: node <T> * hnode. //hnode stands for horizontal link to the node
3. template <class T>class node :: node <T> * vnode. //vnode stands for vertical link to the node
4. template <class T>class node :: short int num data. //For tracking node positions


About the code:

sparse is defined as a generic class having

Data variables:

public:
     node <T>* root;
private:
    node <T>* temp;
    int m, n; // to define the maximum size of the sparse matrix


Member Functions:

public:
    sparse();//Constructer
    void insert(int case, T a, int posva,int posha);//for insertion
    void display( void ); //lots of bugs to be fixed in this function
private:
    int insertion ( case 1 , node <T>* a , int pv , int ph )
    int insertion ( case 2 , node <T>* a , int pv , int ph )
    int insertion ( case 3 , node <T>* a , int pv , int ph )
    int insertion ( case 4 , node <T>* a , int pv , int ph )
    int index_return( int ret = 0 , node <T> * a)
    int index_return( int ret = 1 , node <T> * a)


More recent definitions to the code


/* incase i = insertion ( casei )
 *
 * incase 1: when at both positions root->vnode[pv].hnode and  
 * root->hnode[ph].vnode, don't have any node associated with 
 * them
 *
 * incase 2: when root->vnode[pv].hnode is occupied and
 * root->hnode[ph].vnode is free
 *
 * incase 3: when root->hnode[ph].vnode is occupied and  
 * root->vnode[pv].hnode is free
 *
 * incase 4: when both root->hnode[ph].vnode and 
 * root->vnode[pv].hnode are occupied
 *  
 * index_return(0, ... ) returns the current vertical position
 * ( assumed that the mxn matrix created is similar to a 
 * a standing grid )
 *
 * index_return( 1 , ... ) returns the horizontal position of the 
 * node in the matrix grid 
 */


Please suggest me more functions which I may write for increased usability.

Wednesday, May 25, 2011

Adding a new GSM Network to Ubuntu

Connecting a GSM network in ubuntu, no problem! Follow the following steps :

1. Open Network Connections, either from network applet or System->Configuration [in ubuntu].
2. Select tab 'Mobile Broadband'.



3. Click on add, a wizard opens for New Mobile Broadband Connection.


 
4. You would be prompt to select Country, Service Provider and plan.


5. On completion of the wizard, a new window would open, leave it as it is.


6. You may change the settings ( also known as dial-up settings ) in window above.
7. And yes, don't forget to check Available to all users. Enter password when prompted.


 8. Select network applet, select your newly created connection.


9. Enjoy Networking :)



Comment on this thread if not connected