• Securing with Port Knocking

    Recently I discovered that my log files started growing. The biggest among them was btmp, which was over 600MB. Attempting to run

  • Suspending a computer over SSH

    I wanted to use an automated script to suspend all nodes in my ubuntu cluster. I decided to use the SSH to send a pm-suspend command to do it. The results were unexpected.

  • Bootstrap Like Responsive CSS

    Several years back, I created my web based CV. It was an awesome website and I was very proud of it. Here are a few screen shots -

    Education - as seen on a desktop

    Education - as seen on a desktop

    Project - as seen on a desktop

    Project - as seen on a desktop

    Work - as seen on a desktop

    Work - as seen on a desktop

    I was very proud of this and told the first person I met to check it out. He whipped out his phone and went to the URL - https://bharath.lohray.com/cv. The page I saw was a huge disappointment!

    Education - as seen on a mobile device Project - as seen on a mobile device Work - as seen on a mobile device

    I had not given a single thought to how the site would look on a mobile device. After all the efforts I had put to get it to work, I had no heart to tweak (rewrite from scratch) the page any further. Now, several years later, I decided to rewrite my online CV this time with the "Mobile First" philosophy in mind. Over the years I discovered that using a pre-built CSS framework was the most predictive way to build a page that would works across all device sizes. I took a special liking to Bootstrap CSS. After a few projects on Bootstrap, I discovered that I was using Bootstrap CSS, jQuery, Bootstrap JS and jQuery UI and add jQuery Mobile to the mix if it were a mobile website.

    In spite of all the libraries bloating my page, I still did not get every thing I wanted. I was hesitant to modify any of Bootstrap CSS files as this would be a major hurdle to upgrading Bootstrap with newer versions. So, I decided to take the best of Bootstrap CSS and make it my own. And the best of Bootstrap CSS is it's responsiveness!

    /*
    A CSS skeleton extracted from bootstrap.css to define responsive classes.
    Make sure you define classes for each screen size and you should have a responsive design :-)
    */
    
    /* print */
    @media print {
    }
    
    /* xs */
    @media (max-width: 767px) {
    }
    
    /* sm+ */
    @media (min-width: 768px) {
    }
    
    /* md+ */
    @media (min-width: 992px) {
    }
    
    /* lg */
    @media (min-width: 1200px) {
    }
    
    /* sm */
    @media (min-width: 768px) and (max-width: 991px) {
    }
    
    /* md */
    @media (min-width: 992px) and (max-width: 1199px) {
    }
    
    /* some deprecated IE stuff - don't worry about it! */
    @-ms-viewport {
    }
    

    Here is the gist containing the code.

    This CSS skeleton extracted from bootstrap.css lets me fill in my styles across the various screen sizes and bring responsiveness to my pages with the greatest ease. Here are the results of my 3-2-1 fall back multi-column CSS - very impressive!

    Large device

    Large device

    Large device

  • On Demand Offline Backups

    I have a few monthly digital magazine subscriptions that I have been getting for years. I have saved and aggregated on my hard disk. Recently, I lost a chunk of these due to my mistake at the terminal. As a precaution, I had these sync to my cloud storage space on hubic (Offer 25GB of storage space + 50 with 5 referrals). I thought I hand a second copy secured. However, as I logged in to the hubic web interface, I saw files vanishing right before my eyes. The hubic client program syncing between my computer and the cloud was sending instructions to get rid of files that were no longer on the computer. By the time I could log in via SSH and terminate the client program, it was too late. Unlike Dropbox, hubic does not keep deleted files to undelete. Years of aggregated magazine subscriptions lost in minutes.

    This made me see the necessity to have offline backups.

    One easy way was to set cron tasks to periodically copy certain folders to an external drive via rsync. However, leaving an external drive connected does turns this "offline" approach into "online". I felt, it would be ideal if I could plug in my drive into my NAS whenever, I wanted and this would cause a backup job to start running. I looked around and discovered that I could use udev, but reading more, I decided I did not want to dive into udev for this.

    I finally settled on an idea, where I plugin my hard disk into the NAS whenever, I wanted to back up and that night, the selected folders would back up to the hard drive. The next morning, I could unplug the disk and voila, I have my little offline backup system.

    I set about implementing this using a shell script that would run every night and check, if my external USB backup, is plugged in or not. If found, it would initiate a backup sequence. Here is the shell script that I used -

    #! /bin/bash
    PART_ID="926fc38e-bc7e-467a-953e-25c6555939a0"
    now=$(date)
    echo "===== Running at $now ====="
    if [ -b /dev/disk/by-uuid/"$PART_ID" ]; then
            echo "Partition Found!"
            mkdir ~/$PART_ID
            mount $PART_ID
            if [ $? -eq 0 ]; then
                    echo "Mounted"
                    # Run backups
                    rsync -r "/home/bharath/hubic/Datasheets" ~/$PART_ID/.
                    rsync -r "/home/bharath/hubic/Harvard Business Review" ~/$PART_ID/.
                    rsync -r "/home/bharath/hubic/IEEE Computer Magazine" ~/$PART_ID/.
                    rsync -r "/home/bharath/hubic/Linux Journal" ~/$PART_ID/.
                    rsync -r "/home/bharath/hubic/MagPi" ~/$PART_ID/.
                    rsync -r "/home/bharath/hubic/Make Magazine" ~/$PART_ID/.
                    rsync -r "/home/bharath/Photos" ~/$PART_ID/.
                    rsync -rl "/home/bharath/Datasets" ~/$PART_ID/.
                    sync
                    umount $PART_ID
                    pushb "Offline backup done."
                    if [ $? -eq 0 ]; then
                            echo "Unmounted"
                            rm -Rf ~/$PART_ID
                            now=$(date)
                            echo "===== Done at $now ====="
                    fi
            fi
    else
            echo ":-("
    fi
    

    Here is the gist containing the code.

    To have this script work, I had to add a line allowing users to mount the disk in the /etc/fstab file.

    UUID=926fc38e-bc7e-467a-953e-25c6555939a0       /home/bharath/926fe38e-bc7e-467a-959e-25c6535939f0      ext4    noauto,noatime,nodiratime,relatime,user 0       1
    

    Apart from this, I had to set the user bharath (me!) rwx permissions on the entire disk. A big problem with doing this is that If, I move the disk to a different computer - one that does not have the user bharath (me!) created with the user id of 1000, someone else, who has UID=1000 would have the rwx permissions. This is something, I would have to live with till I figure a way around this or write my own portable journaling file system.

    To perform a nightly check, I would have to add something like the following line to my crontab -

    0 4 * * * /home/bharath/do_offline_backup.sh >> offline_backup.log
    

    On a side note, comparing hubic to Dropbox, I see hubic having a huge price advantage -

    hubic Dropbox AWS S3 (Oregon)
    €10/year (100 GB) $100/year (1TB) $370/year (1TB)
    €50/year (10 TB) + Data transfer cost

    * 2016 October Prices

    And hubic servers are hosted in France, we can reasonably hope that this in out of reach of the various 3 letter government agencies of the US.

    The downside of hubic are -

    1. Speed - it is slightly slower than dropbox.
    2. UI - not as great a UI as dropbox.
    3. Versioning - no versioning or undelete.
    4. Dropbox paper - no on website editors with hubic.

    If all you want to do is have an online cloud backup, this is the service for you.

  • Hardcoding Passwords and git

    Recently I was working on building myself a script to download my securities transactions from Robinhood and save it as a CSV. I found an unofficial python library that was reverse engineered from the app. As I started building the script, I realized that I could not host it on git. I had hardcoded my credentials in the code.

subscribe via RSS