Today, I had the necessity to embed an iframe on an HTTPS web page and most browsers now won't allow you to embed an HTTP resource on an HTTPS page raising the mixed content warning. Since the code was quite experimental, I didn't want to deploy it out of localhost. So I setup a self-signed TLS certificate for localhost that was accepted by Google Chrome browser.

First, we need to create a key that will be used to sign our certificate. You will be prompted for a password, which you can enter for now:

openssl genrsa -camellia256 -out server.key 2048

Let's remove the passphrase from the key now:

cp server.key server.key.orig
openssl rsa -in server.key.orig -out server.key

Next, we need to create a certificate signing request (CSR) with the above created key. Enter the information you are prompted for:

openssl req -new -key server.key -out server.csr

Create a certificate with validity of 365 days for the above CSR:

openssl x509 -req -sha256 -days 365 -in server.csr -signkey server.key -out server.crt

You can use the above server.key and server.crt in any web server or application of your choice.

Create a single file with the certificate and private key to be added into the store:

cat server.key server.crt > localhost.pem

Finally, add this certificate into our trusted store so that Chrome doesn't complain:

certutil -d sql:$HOME/.pki/nssdb -A -t "C,," -n "localhost" -i localhost.pem

Your browser shouldn't complain any more with your self-signed certificate successfully added into the store.


Elasticsearch autocomplete on related keywords

Thu 21 April 2016 by Thejaswi Puthraya

Recently, I had to work on a client request to add autocomplete to their site's search based not just on a specific list but on related keywords.

For example, suppose you had a list of TV series like Simpsons, Futurama, Tom and Jerry etc. The autosearch had to suggest the …

read more

Simple Command Line Dropbox Uploader in Python

Sun 10 April 2016 by Thejaswi Puthraya

I don't use Dropbox frequently. In fact, I would prefer not to use it but work requires me to use it from time to time. My only use case was to upload files onto a shared folder. So for my usage, it makes no sense to run the desktop client …

read more

Nginx Basic Auth without htpasswd-tools

Mon 10 November 2014 by Thejaswi Puthraya

Sometimes you may want to hide your staging server or project under development from search engines and prying eyes but you don't want to take a lot of pain. HTTP Basic Auth is one solution (can be used as a proper authentication mechanism for web-apps as well) to allow only …

read more

Resize Qemu Image

Wed 30 October 2013 by Thejaswi Puthraya

The default cloud image on Ubuntu has a root partition size of 2GB. I wanted a way to resize the root without going through the hassle of setting up LVM.

To be able to resize the qemu images, we need the Guestfish package.

qemu-img create -f qcow2 -b base_disk.img …
read more

Upload a directory to Rackspace Cloud Files from command line

Wed 02 January 2013 by Thejaswi Puthraya

Here's a simple bash script that uploads a directory to Rackspace Cloud Files and may later on be served as a static website.

First we have to authenticate to get the authentication token that has to be passed for every request:

$ curl -v -X GET -H "X-Auth-User: <username>" -H "X-Auth-Key …
read more

The missing documentation for django.utils.datastructures

Thu 01 November 2012 by Thejaswi Puthraya

Cross posted from my work blog.

Note

django.utils.datastructures is intentionally not documented by the django core devs because it is an internal API and is liable to change without any notice. This file is not governed by django's lenient backwards-compatible policy. You have been sufficiently warned!

With the …

read more

Dissecting Phonegap's architecture

Thu 06 September 2012 by Thejaswi Puthraya

Cross-posted from my work blog.

Apache Cordova is a open source cross-platform framework for building native mobile applications using HTML, CSS and JavaScript. It started off as Phonegap, a project of Nitobi Software before it was acquired by Adobe Systems. The code for the platform was donated to the Apache …

read more

Dropbox file upload handler for django

Tue 17 July 2012 by Thejaswi Puthraya

Cross posted from work blog.

Dropbox announced new pro plans last week and some accounts have had their storage size doubled. Wouldn't it be wonderful if we could upload all our files to dropbox from our django webapp?

In this post, I write a custom file upload handler that will …

read more

Using Ubuntu cloud images in KVM

Mon 16 July 2012 by Thejaswi Puthraya

Cross posted from work blog.

Quite a few of our clients are powered by Amazon EC2 or Rackspace and we use Ubuntu LTS releases for our servers. Canonical provides EC2 AMIs and Openstack images for all their releases. By using these JeOS images on the server as well as on …

read more