Skip to content

Instantly share code, notes, and snippets.


Sandip Bhattacharya sandipb

View GitHub Profile
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
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 Sep 27, 2021
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
sandipb /
Last active Aug 5, 2020
Example code to use the Golang httprouter library
sandipb /
Created Jun 21, 2020
Bash script to generate new server certificates and private key, for the OpenSSL Certificate Authority guide by Jamie
# set -x
set -e
cd $(dirname $0)
# The path to the homebrew install on mac. Change to point to your own installation
NAME=${1:?Need a hostname for generating certs}
export SAN="DNS:$NAME"
sandipb /
Created Jun 12, 2019
Benchmarking json loading across json and ujson (precision floats and normal)
import json
import ujson
from timeit import repeat
def decode_json(data):
def decode_ujson(data, precise=False):
sandipb /
Last active Jun 11, 2019
ujson repr trips up json dumps
from __future__ import print_function
import ujson, json
data = '{ "prod-lsg1": { "max_float": 0.0046288111 } }'
print("json dumps, w/o precise float: ", json.dumps(ujson.loads(data)))
print("json dumps, w/ precise float: ",json.dumps(ujson.loads(data, precise_float=True)))
print("ujson dumps, w/o precise float: ", ujson.dumps(ujson.loads(data)))
print("ujson dumps, w/ precise float: ",ujson.dumps(ujson.loads(data, precise_float=True)))
sandipb / .bashrc
Last active Oct 11, 2018
Bashrc to keep a consistent tmux ssh-agent environment
View .bashrc
SOCKPTR="$(readlink -f $SOCK 2> /dev/null)"
if [[ -z $SOCKPTR ]] || [[ ! -S $SOCKPTR ]]
echo -e "\e[31m\e[1mNo valid current tmux ssh-agent link\e[0m"
if [[ -n $SSH_AUTH_SOCK ]] && [[ -S $SSH_AUTH_SOCK ]]
rm -f $SOCK
View gist:49f91868e83de9db70238dadfd0d80ca
### Keybase proof
I hereby claim:
* I am sandipb on github.
* I am sandipb ( on keybase.
* I have a public key ASC4KMgsBE9a3n9l9GI0InNtbh-SzM49e_m3sNt7jlAY4Qo
To claim this, I am signing this object:
sandipb / main.go
Last active Mar 22, 2018
Golang web handlers and sigpipe
View main.go
package main
import (