Category Archives: Programming

Taking backup zip from multi-module Java project

I like to keep an archive of my code on a monthly basis. I wrote a small bash script to create zip out of my multi module Java projects. It gets the job done and can be improved to include resources and test folders as well. As of now I am only interested in the Java code zip backup.

!/bin/bash
 if [ -d "combined" ]; then
     echo "Removing existing zip files in combined .."
     rm combined/*.zip
 else
     echo "Creating combined folder.."
     mkdir combined
 fi
 for d in */ ; do
     if [ -d "$d/src/main/java" ]; then
         var="$(echo $d | sed 's/.$//')"
         echo "Processing $var .."
         cd $d/src/main/java
         zip -r ../../../../combined/$var.zip com
         cd ../../../..
     else
         echo "Ignoring .. $d"
     fi
 done

Triggering download of file using JavaScript

I recently needed to write a small piece of download code. So you pass in the ID of the document to a REST API and it should give you back a blob of the actual file. The problem however is how to actually save this blob of binary data into a local file. So a quick Googling threw up some interesting links which I finally used to finalize my solution.

Code to detect file name

Code to trigger download

Fractal Folders

I have asked myself this question a number of times. What is the best possible way to structure my UI code? Should I cluster the files using functionality or by the type of file? etc. etc.

I found a partial answer in Fractal Folders while learning ReactJS. This basically proposes that for an UI page there are many functionalities which it is comprised of and the artefacts related to these sub-functionality should be clustered as sub-folders.

 

Export JSON from RoboMongo

I use RoboMongo extensively for all my Mongo development work / debugging. I however sorely needed a way to export JSON from it. A Stack Over Flow link came up in a Google search and I was able to export JSON for my use. Basically you need to execute this command which uses “printjsononeline” function provided by Mongo to give you one line JSON for each row in the collection:

db.getCollection('collection_name').find({}).forEach(function(x){printjsononeline(x)});

Installing pip on MacOS

I recently started exploring python and immediately ran into the following issue:
$ pip install requests
-bash: pip: command not found

A quick google search yielded this result. So basically on MacOS you have Python preinstalled along with easy_install command. So the following command installs pip:

$ sudo easy_install pip
Searching for pip
Reading https://pypi.python.org/simple/pip/
Best match: pip 9.0.1
....
....
Processing dependencies for pip
Finished processing dependencies for pip

A quick and handy solution indeed!