Skip to content

Instantly share code, notes, and snippets.

View gsidhu's full-sized avatar

Gurjot Sidhu gsidhu

View GitHub Profile
gsidhu /
Created August 24, 2023 08:28
Somebody sent you a WordPress site in a zip file. You want to run it locally. How do you do it?

What I received:

  1. A zip file containing a WordPress site.
  2. A .sql database file.

I figured that the .sql file is the WordPress database.

How to get shit running:

  1. Set up an Ubuntu virtual machine. Why virtual machine? So you get a contained sandbox and a clean slate for your experiments. Why Ubuntu? It's just a whole lot easier to do these things on Linux. Screw your MAMP and WAMP stacks.

  2. Install nginx, mysql-server and php7.4. That's your LEMP stack right there.[^1] DigitalOcean tutorials can help you set these things up. Use php7.4 because most of the Internet breaks on php8.1. You'll need to add a new ppa package for that - DigitalOcean can tell you how. All the additional php packages that you install should also have the php7.4 prefix in front of them. If you install php-fpm you might just get php8.1-fpm. S

gsidhu /
Created September 23, 2022 08:09
Mapping Datawrapper country names with Wikipedia / UN list

If you're trying to make a population map using Datawrapper, this list might be helpful to match data between Wikipedia and Datawrapper.

• Datawrapper country names from • United Nations / Wikipedia country names from List of countries by population (United Nations)

Datawrapper Country Name UN / Wikipedia Country Name
Afghanistan Afghanistan
Albania Albania
Algeria Algeria
gsidhu /
Created September 4, 2022 16:28
How to set up FTP and SSH on a new machine

Note: These instructions are for my future self.

Assuming you have a remote server with the following details –

IP Address:
Username: rockstar
Password: ********
gsidhu /
Last active August 24, 2022 13:57
Create a pivot table in R

If you've got data that looks like this –

S.No. UID District Block Age Gender Social Category
3 239140003 KOLKATA WARD 72 7 BOY SC
6 239140006 KOLKATA WARD 101 8 TRANS OBC
gsidhu /
Created February 13, 2022 21:32
Boiler plate code for uploading files to Google Drive
# install dependencies listed here:
from googleapiclient.discovery import build
from google.oauth2.service_account import Credentials
from googleapiclient.http import MediaFileUpload
# Location of the access token
# Get this from
ACCESS_TOKEN_LOCATION = "client-secret.json"
# Check the scope for your needs at
gsidhu / leaflet-reset-zoom-button.js
Last active July 12, 2021 20:46 — forked from stefanocudini/leaflet-reset-zoom-button.js
leaflet reset zoom button
// preview what this looks like:
(function() {
var control = new L.Control({position:'topleft'});
control.onAdd = function(map) {
var azoom = L.DomUtil.create('a','mt-0');
azoom.innerHTML = '<div class="leaflet-control-zoom leaflet-bar leaflet-control mt-0 ms-0"><a class="leaflet-control-reset-zoom" title="Reset zoom" role="button" aria-label="Reset zoom"><svg xmlns="" width="16" height="16" fill="currentColor" class="bi bi-house" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M2 13.5V7h1v6.5a.5.5 0 0 0 .5.5h9a.5.5 0 0 0 .5-.5V7h1v6.5a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 2 13.5zm11-11V6l-2-2V2.5a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 .5.5z"/><path fill-rule="evenodd" d="M7.293 1.5a1 1 0 0 1 1.414 0l6.647 6.646a.5.5 0 0 1-.708.708L8 2.207 1.354 8.854a.5.5 0 1 1-.708-.708L7.293 1.5z"/></svg></a></div>';
.addListener(azoom, 'click', function() {
gsidhu /
Last active June 20, 2021 13:12
How to self-host Commento on your server

How to self-host Commento on your server

Commento is an open source commenting service. It is privacy first and lightweight.

Commento++ is a fork that I highly recommend. It has some nifty features like commenting with a name instead of logging in (side note: I use this feature as a proxy for SSO on one of my projects).

Here's how to self-host it on your server.

The Structure

There are five main steps to this –

  1. Setting up PostgreSQL.
gsidhu /
Created June 18, 2021 13:06
Access Google Sheets using a Service Account API Key
The sample Python Quickstart code on Google Developer's site only shows how to access a Google Sheet using OAuth credentials. But that feels like an overkill when you simply want to read data from a sheet.
This code does just that.
## What is this code snippet useful for?
This code snippet serves the following use-case:
1. You want to simply READ data from a Google Sheets document
2. You don't want to set up OAuth and instead want to use the Service Account API that lets you plug the API key in for making requests