Always fetch upstream!

Welcome to n00bsland!

Everybody should remember where there come from. Including their repos.

Why you ask? Becase git merge :/

I recently edited a few files in my branch of a repo and created pull request. Well guess what? The master had moved forward.

So the usual-

1. Delete local repo

2. Add remote upstream

git remote add upstream

3. Update local copy.

git fetch upstream

4. Create changes (again >_<)

5. Commit and pull.

Don’t be a n00b, always add upstream repo.

Getting started with Raspbian – First touches

Disclaimer : All the knowledge here has been scoured from the internet.

So I got myself a Raspberry Pi 2 this month. But due to some display connectivity issues (lack of HDMI monitor, USB keyboard,etc) on my part, I was unable to use it.

Finally now though, I have got it up and running. But there are a few customizations (and fixes) that I had to do before it became usable for me.

1. The terminal hotkey 

My number one problem was that there was no terminal hotkey (that launched in the same x session). I sorely missed that, needing to click on the taskbar icon and then shifting onto the keyboard to type the update and install commands.

Adding the shortcut is no biggie. Do the following:

    sudo leafpad ~/.config/openbox/lxde-pi-rc.xml

Find the tag and paste this line just before it:

and restart.

2. The youtube play icon
So there is a glitch in epiphany because of which the play icon of youtube doesn’t really go away.
5 seconds since the video started
So I just installed midori and now that’s my default browser.
sudo apt-get install midori
3. Headphones audio not working
This required configuring from the rasp-config utility.
sudo raspi-config 
Goto Advanced Options -> Audio -> Force 3.5 mm.
I’ll keep adding as and when I find something worth sharing.

A trick for Rough work

I use a lot of my notebooks and registers and write a lot of rough notes at the back pages while I am thinking or practicing.

The one problem I was faced was with how to jot down longer notes, like programs, derivations or simply anything that ran much longer than a page, because then I’d be forced to write stuff in reverse order (E.g – begin on page 320, then goto page 319 when I run out of space, etc).

So a simple way to write rough notes would be to start upside down.

Instead of writing in the usual fashion, rotate your register/notebook by 180o.

This has the advantage that you can continue to the next page, which is actually the previous page on your notebook, but still maintain readability.

Double Factorial

So today while reading wiki for graph algorithms, I came across this term n!! called double factorial. Naturally, I was petrified. A factorial time complexity is scary enough, how horrible would double factorial be? In my mind I was assuming all sorts of irrational expressions such as:

n!! = (n-1)!!(n-1)!!
     = ((n-2)!! (n-2)!!)( (n-2)!! (n-2)!!)
     = … [You get it, right?]

But as it turns out, double factorials are not so bad after all. Actually:

n!! = n*(n-2)* (n-4)*(n-6)*…

With terminal conditions 0!! = 1!! = 1.

So, a double factorial is actually has similar complexity to sqrt(n!).



LeetCode – Q214 – Shortest Palindrome

This question, despite being solvable by a simple O(n^2) algorithm, almost took 2 hours of my life.

Simply because I was trying to get sub-palindromes, when instead, I should have checked for longest prefix of original string matching the suffix of its reverse.

E.g.           s = “abcda”

              reverse of s = rev = “adcba”

         longest suffix of rev matching s = “a”

              Answer = “adcbabcda”

class Solution {
    string shortestPalindrome(string s) {
        string rev = s;
        int n = s.size();
        for(int i=n;i>0;i–)
                return rev.substr(0,n-i)+s;
        return rev+s;

Round-off in C (C++ too)

I think the best way to round off decimals in C for output would be to simply adjust the accuracy in the printf function. The following code demonstrates that-


float a = 3.56449;
One thing though, you don’t get rolling round-offs, i.e, 3.56449 becomes 3.564 and not 3.565.