Posts
Backward Compatibility!
· β˜• 4 min read · πŸ€– Naresh Mehta

Backward Compatibility

The internet is littered with articles on backward compatibility and why it is important and rants of people who work/use 1970s systems on the same. Well the last sentence there was a pun but people do rant on not being able to use the PS2 games on PS4 and or not being able to use Lint with the new c++11 or c++14 features or sticking to an outdated kernel (2.6.36) and not being able to use the new virtual environment enhancements, etc. Finally, all of these rants boil down to, “Everything should be backward compatible and should not break existing systems”.


Basic use of Tuples C++11
· β˜• 2 min read · πŸ€– Naresh Mehta

Basic use of Tuples in C++11

Tuples are an amazing feature in C++. Tuples are specified inΒ C++11 standard (ISO/IEC 14882:2011), i.e. they are a new introduction in c++11. So if you are more used to traditionalΒ c++, tuples will come as a surprise for you. It happened to me as well and I am not that old (quite yet)! They are a great addition to generic programming and brings C++ to a whole new level of usability. Of course we have had ways to do exactly the same things that tuples does but now that it is a part of the standard language, it makes sense to use this feature instead of cooking something of our own. I see tuples as an important feature like dictionary in python (more or less). Tuples are amazing and you can feel the power when you start using them. Auto types and tuples make a great combination for very nice cool features previously rarely thought of (multiple return values from a function anyone). Anyways, I don’t see people really appreciating the flexibility being provided by our beloved language. Stefan Lavavej (@StefanTLavavej) maintaining the STL implementation, working at @microsoft, has a very nice talk in CPPCon 2016 that I recommend you watch. Check it out below. This is the one that got me interested in tuples.


Ranged Switch Case C++
· β˜• 2 min read · πŸ€– Naresh Mehta

Ranges in C++ Switch Case block

Today, we will do something really stupid! Yes, I am talking about the ranged switch case support that is available in C++. In all the commercial/hobby source code that I have seen, implemented and used, rarely have I come across the ranged switch case use. Most of the code when in need of ranges inside a switch case start using multiple case cascading or (the more niche programmers) resorting to nested if..else blocks!
So much so that when I told one of my co-workers that we can use ranges in C++ switch case, he started laughing (hysterically if I may add). Taken aback, I wanted to see if I have learned stuff wrong. So here it is, just to brush up your basic cpp knowledge and fall in love with it again! Below is the code in ideone ready for you to take for a spin.


Simple Downloader!
· β˜• 2 min read · πŸ€– Naresh Mehta

I come across this very nice siteΒ http://www.dwarkadheeshvastu.com/Β which has a collection of excellent MP3s (Devotional Music). I congratulate the maintainer of that site for the excellent collection of texts/mp3s in multiple languages. So the site is more or less static with mp3s arranged inside folders starting from 000.mp3 to the <lastsection>.mp3. And you want to download them all.

Layman way is to keep right clicking on each link and do save as. But we are lazy programmers. We will just give our job to the computer to increment the URL and download the file for us. This can very simply be done in a bash script. Below is a snippet. I will not go into explaining all the details, just that the script takes in 3 parameters (start of the count, end of count and the absolute URL of the folder). Run the script and get all the mp3s that you need. One can extend the script to pass in the kind of file we are interested in (like mp3, pdf, etc.). But that is left as a user exercise. The folder path can be got by looking at the HTML code (in case you are wondering how I got it).


Forgot your EXCEL Password?
· β˜• 2 min read · πŸ€– Naresh Mehta

Okay. It is a bit sneaky and I will not explain everything but if by any chance you are using Excel and are password protecting the sheets and if you forget what your password was, β€œYou are dead… ;)”. NOT REALLY! Use the following VBA script to recover the password. No need to download any softwares. Just press Alt+F11, put in the code and run it. It will soon pop up a box with the actual password which you can use to unlock.


SSHFS on Linux & Windows
· β˜• 2 min read · πŸ€– Naresh Mehta

SSHFS does come into play when connecting to a remote client and/or working on a remote server. I am pretty sure most of you are aware of how to do this. But if not, the below can help a lot with your development using your favorite tools. The problem is that on the remote servers is either not having root access, or updated and latest software and/or most of our new age tools might not work as expected (eg: try to run atom on it or sublimeText). Also using NX is pain… You can of course run Linux or X-Server on windows and get native X-forwarding but losing the SSH session will invalidate your window and you might have data loss. Worst of all, such X-sessions are not restored (on windows).


Angular2: Beyond the β€œTodo” list!
· β˜• 6 min read · πŸ€– Naresh Mehta

Angular2 is the latest buzz word in web programming and frankly speaking, I am in love with it. It seems to be the β€œDocker” for web! Well I am also in love with β€œDocker” and the good part is that both Angular2 and Docker do not mind me loving them at the same time ;). Jokes apart, I particularly like Angular2 because of the component concept and its inherent support for TypeScript (TS). Components truly allow for creation of re-usable web components since they also encapsulate the β€œview” aspect. Hence no more grappling / switching between a model/view/controller. Everything is inside a component. You use the component and you get an automatic binding with the needed controller and view. This takes re-usability to the next level. Also for someone like me whose background is systems programming, components can be seen as class object exposing certain methods/properties (i.e. basic encapsulation). Components also allows for extension (i.e. inheritance) and can be tested individually, so once confirmed working, they are always working without any external dependency. That said, there are quite a few tutorials out there which creates a basic ToDo app with Angular2 and yes, it is pretty cool. But when you try to make something useful out of what has been learned from the ToDo App, the details bog us down. In any case, #FreeCodeCamp (#FCC) project on Pomodoro Clock was my trigger to use Angular2. I have the project hosted on Plunker (Pomodoro Clock) which uses Angular2, TS and Semantic-UI. I am also a big fan of Jade so have used it a little bit in the index.html but using it inside a component template seems to be a bit awkward. Though we can do so, I have used normal HTML since the components are broken down and are quite simple. Pomodoro clock is basically a countdown timer which alternates between a session time and break time and increases productivity (Google it if you want to know more).


Get Started With Docker!
· β˜• 4 min read · πŸ€– Naresh Mehta

Docker is amazing! It is a gift to mankind. Next best thing after sliced bread! Lets start using it yeah. OK, lets say you want to get started with docker quickly and install a host of services on your local machine that enables you to get your big-data analytics SW into a real-time visualization. Don’t go about searching the net on how to install different servers. Instead, use Docker (I bet you knew this was coming)!