Skip to content

The Lacuna Blog Posts

Grab PacktPub Free Learning eBook Everyday Automatically

Packt Publishing have a lot of good premium books and everyday they put up a premium book for download for free. You could get a premium book a day by going to the Free Learning eBook page. I chose to automate the process and have the book grabbed automatically to my PacktPub account everyday. I have made the script available on Github for anyone who is interested to do the same: PacktPub Grabber.

read more

Convert Fortinet's Fortiguard WebFilter logs to CSV Format

I put together this script called csvify_fortinet_logs in order to convert the space separated format of Fortinet Router's Fortiguard WebFilterLog to a more widely used and favorable for analysis format, CSV. I wanted to analyse the web filter log of the router, but could not use it as an input to pandas, so had to code this.

What the script does is, convert the log from following transaction format:

date=2016-04-29 time=16:19:33 logid=0316013056 type=utm subtype=webfilter eventtype=ftgd_blk level=warning vd="root" policyid=16 identidx=1 sessionid=29075420 user="x_y" group="bla bla" srcip= srcport=60957 srcintf="LAN-NW-2" dstip= dstport=80 dstintf="wan2" service="http" hostname="" profiletype="Webfilter_Profile" profile="Student" status="blocked" reqtype="referral" url="/?id=461665" sentbyte=739 rcvdbyte=535 msg="URL belongs to a denied category in policy" method=domain class=0 cat=26 catdesc="Malicious Websites"

date=2016-04-29 time=16:15:27 logid=0316013056 type=utm subtype=webfilter eventtype=ftgd_blk level=warning vd="root" policyid=16 identidx=1 sessionid=29017201 user="x_y" group="blabla" srcip= srcport=60319 srcintf="LAN-NW-2" dstip= dstport=80 dstintf="wan2" service="http" hostname="" profiletype="Webfilter_Profile" profile="Student" status="blocked" reqtype="direct" url="/e?i=43" sentbyte=429 rcvdbyte=0 msg="URL belongs to a denied category in policy" method=domain class=0 cat=72 catdesc="Peer-to-peer File Sharing"

read more

List of Nepali data sources

Hi guys, its been a long time. I am tired of making empty promises (regarding posting regularly) so, let me not do it again. While I was beginning my data-science journey, I tried to collect as many sources for Nepali datasets as possible, and the following is the listing of the same. The problem is most of these datasets are in PDF (most are in a booklet), so you'd have to use some extraction utilities such as Tabula to convert it into a CSV or workable file format.

read more

Websites That Offer Free Shipping To Nepal (and Worldwide!)

Black Friday and Cyber Monday are over (and apparently Green Monday too). On these two days, western stores offer huge discounts on products. I was looking to make some purchase, but could not find a deal with free International shipping. Buying from stores, mostly those that are based on western countries, would cost you almost twice the actual amount just for sending the shipment. Some sites don't even offer paid International shipping, in which case, you have to use a reship service and that would cost you lots of dough.

read more

How To Batch Crop & Straighten Scanned Photos?

I spent the last two days scanning photos from my family albums (about 900 photos). Scanning each photos individually will take lots of time, however not any further processing is needed. When you scan multiple images at once, you need to crop and straighten each photo from a single page you scanned.

With the scanner I had, I could fit 4 photos and scan them at once. And so I did. I chose it over scanning each photos individually because there are some tools to automagically crop photos from a group of scanned photos.

One thing that is very important in order to split photos is to make sure that there is some gap between the photos. Meaning, when you put the photos in the scanner, there should be a uniform background that separates each photos. They should not be overlapping, or touching each other. The splitter tools crop the photos based on where the background begins and ends, so this is important.Here are the tools that can help you to auto-split scanned images by batch cropping (and straightening) them. I have listed 6 tools here, two of which can be used on Linux, and four can be used on Windows (& some on mac).


To access this feature, you can go to File > Automate > Crop and Straighten Photos.

But, what if you have multiple scans, and you need to split them into single images like in my case?

Luckily, I found a PS script that does this for you.

#target Photoshop
var inFolder = Folder.selectDialog("Please select folder to process");
if(inFolder != null){
var fileList = inFolder.getFiles(/.(jpg|tif|psd|)$/i);
var outfolder = new Folder(decodeURI(inFolder) + "/Edited");
if (outfolder.exists == false) outfolder.create();
for(var a = 0 ;a < fileList.length; a++){
if(fileList[a] instanceof File){
var doc= open(fileList[a]);
var docname = fileList[a].name.slice(0,-4);
var count = 1;
var saveFile = new File(decodeURI(outfolder) + "/" + docname +"#"+ zeroPad(count,3) + ".jpg");
SaveJPEG(saveFile, 12);
activeDocument.close(SaveOptions.DONOTSAVECHANGES) ;
function CropStraighten() {
executeAction( stringIDToTypeID('CropPhotosAuto0001'), undefined, DialogModes.NO );
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;

read more

JetBrains' Products Now Free For (Nepali) Students

A little late in sharing this wonderful news. If you don't know yet, JetBrains, the developer of awesome IDEs like IntelliJ IDEA and PhpStorm have made their products free for students. And guess what? This is unlike other free-for-students offer. Most of the free-for-students discounts are limited to students of US university and colleges only. The way to check whether a person claiming to be a student to avail these sorts of discounts is in fact a student or not, is to make him use his university provided email address.

read more

How to login to a website via Google Script?

Whenever I have to accomplish something these days (in terms of programming that is), the language that I turn to at first is Google Script. I have gotten so used to it, and its interface that I prefer it over any other language, or services. The added bonus of using it is that you can run the script regularly by setting up a timer. No need to meddle with cronjobs and what-not on your server.

Some time back, I was trying to login to my college's LMS (Learning Management System) using Google Script. My college uses Moodle and it has been setup such that if you do not login for 12 consecutive days, your account will get disabled. Once disabled, you need to go to the authority and bend over your backwards to convince him to re-active your account. I don't login to Moodle very often and neither do my friends. I turned to Google Script to solve this problem, to login to Moodle every week.

You can use the following script to login to any (I hope) website via Google Script.

/**   Published by Subigya Nepal on 09/08/2014    **/

function loginToSite(){
  var url = "enter login URL here"; //change this.
  var payload = {
    "username":"enteryourusername", //change this.
    "password":"enteryourpassword" //and change this. done. no need to enter anything elsewhere.
  var opt = {
    "followRedirects" : false
  var response = UrlFetchApp.fetch(encodeURI(url),opt);
  if ( response.getResponseCode() == 200 ) { //could not log in.
    var result = "Couldn't login. Please make sure your username/password is correct.";
  else if ( response.getResponseCode() == 303 ) { //login was successful. you might receive 302 response code as well depending upon the site. So try changing it to 302.
     var result = "Logged in successfully";
     var cookie = response.getAllHeaders()['Set-Cookie'];     
     var header = {
       'Cookie':cookie[1] //taking the second cookie because when redirected, a new cookie is set. If the page does not redirect, you might need to use cookie[0] here. Try it out yourself!

read more