Skip to content

Instantly share code, notes, and snippets.

View sandipb's full-sized avatar

Sandip Bhattacharya sandipb

View GitHub Profile
sandipb /
Created February 29, 2024 16:07
Python script to pipe text with short urls and have it expand short urls in it
import re
import sys
import requests
def expand_url(match):
short_url =
response = requests.head(short_url, allow_redirects=False)
if response.status_code in (301, 302):
return response.headers["location"]
sandipb /
Created January 17, 2024 14:19
Bash function to use the vs code cli in remote ssh extension
code_remote ()
local remote_node_path=$VSCODE_GIT_ASKPASS_NODE;
if [ -z "$remote_node_path" ]; then
echo "VSCODE_GIT_ASKPASS_NODE is not set. Cannot determine path to remote-cli";
return 1;
local remote_cli_path=$(dirname $remote_node_path)/bin/remote-cli/code;
if [ ! -f "$remote_cli_path" ]; then
echo "Remote CLI not found at $remote_cli_path";
export GCLOUD_TUNNEL_PID=/tmp/gcloud-tunnel-pid
function proxy_bastion() {
local BASTION_HOST="bastion-instance"
local GCP_ZONE="us-east4-a"
[[ -f $GCLOUD_TUNNEL_PID ]] && echo "File $GCLOUD_TUNNEL_PID exists. A previous tunnel might be active. Aborting." && return
set -x
gcloud compute ssh $BASTION_HOST --zone=$GCP_ZONE --verbosity=warning --tunnel-through-iap --ssh-flag='-D1080 -N' &
#!/usr/bin/env bash
# General
# Golang
sandipb /
Created May 10, 2023 21:25
Script to decrypt PDFs using qpdf. Will ask for password only if needed.
set -e -o pipefail
usage() {
cat <<HELP
Decrypts given pdf file usingh qpdf by prompting for a password.
sandipb /
Created April 22, 2023 06:58
How to enable a linux host to route between two lans
# $PRIVATE_IF is private lan, $PUBLIC_IF is public lan
# the interface which is connected to the interface.
# The default route of this host is already set via this interface
# The interface connecting to the internal lan, which needs this host to be a router to the Internet
sandipb / create new django
Last active March 13, 2023 17:52
Creating new django project
View create new django
$ mkdir dtemp
$ cd dtemp
$ poetry init
This command will guide you through creating your pyproject.toml config.
Package name [dtemp]: Django Test
sandipb / age_sorted_names.pp
Created July 20, 2022 13:31
Puppet sort hash
View age_sorted_names.pp
$data = [
{'name'=> 'emily', 'age'=> 6},
{'name'=> 'john', 'age'=> 5},
{'name'=> 'jade', 'age'=> 4},
{'name'=> 'grant', 'age'=> 2},
function age_sorted_names($ar) >> Array {
$ |$idx, $entry| {
[$entry['age'], $entry['name']]
sandipb /
Last active May 5, 2022 02:46
Fix cups-pdf not printing PDFs with restrictions

Fix problem when cups-pdf (actually Ghostscript) refuses to print PDF files with restrictions

Specifically, even if the file has no printing restrictions, like many government forms do (my specific itch), Ghostscript refuses to print the file and generates a blank pdf.

Steps to fix

  1. Put contents of in an executable file named /usr/lib/cups/filter/unblockprint. Make sure that the permissions of this file matches others in the same directory.
  2. Put local.convs in /etc/cups
sandipb / playbook.yml
Created September 27, 2021 22:58
Get non-matching kernels on all hosts using ansible
View playbook.yml
- hosts: ubuntu
gather_facts: yes
kernel_does_not_match: "{{ (ansible_distribution == 'Ubuntu') and ( ansible_kernel != '5.4.0-86-generic') }}"
output_path_local: /tmp/host_kernels
- block:
- name: Add matching host to file