Skip to content

Instantly share code, notes, and snippets.

View gsidhu's full-sized avatar

Gurjot Sidhu gsidhu

View GitHub Profile
@gsidhu
gsidhu / wordpress-local-site-setup.md
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
gsidhu / datawrapper-wikipedia-country-names-list.md
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 www.datawrapper.de • 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
gsidhu / ftp-ssh-new-setup.md
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: 192.168.1.1
Username: rockstar
Password: ********
@gsidhu
gsidhu / r-pivot-table.md
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
1 239140001 HOOGHLY ARAMBAGH 7 GIRL GENERAL
2 239140002 HOWRAH SHYAMPUR-I 2 BOY GENERAL
3 239140003 KOLKATA WARD 72 7 BOY SC
4 239140004 HOOGHLY BALAGARH 3 GIRL ST
5 239140005 BIRBHUM DUBRAJPUR 5 BOY SC
6 239140006 KOLKATA WARD 101 8 TRANS OBC
@gsidhu
gsidhu / upload-to-drive.py
Created February 13, 2022 21:32
Boiler plate code for uploading files to Google Drive
# install dependencies listed here: https://developers.google.com/drive/api/v3/quickstart/python#step_1_install_the_google_client_library
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 https://console.cloud.google.com/apis/api/drive.googleapis.com/
ACCESS_TOKEN_LOCATION = "client-secret.json"
# Check the scope for your needs at https://developers.google.com/identity/protocols/oauth2/scopes#drive
@gsidhu
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: https://imgur.com/a/jmAnZUd
(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="http://www.w3.org/2000/svg" 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>';
L.DomEvent
.disableClickPropagation(azoom)
.addListener(azoom, 'click', function() {
@gsidhu
gsidhu / commento-self-host-setup.md
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
gsidhu / google-sheets-service-account.py
Created June 18, 2021 13:06
Access Google Sheets using a Service Account API Key
"""
## ATTENTION
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