Skip to content

Instantly share code, notes, and snippets.

View sandipb's full-sized avatar

Sandip Bhattacharya sandipb

View GitHub Profile
@sandipb
sandipb / csv_to_avro.py
Created May 20, 2015 10:09
Avro schema for weather data
View csv_to_avro.py
#!/usr/bin/env python
import avro.schema
from avro.datafile import DataFileWriter
from avro.io import DatumWriter
import csv
import calendar
import time
schema = avro.schema.parse(open("weather.avsc").read())
@sandipb
sandipb / main.go
Last active March 22, 2018 00:54
Golang web handlers and sigpipe
View main.go
package main
import (
"bytes"
"flag"
"log"
"net/http"
"os"
"os/signal"
"strconv"
View gist:49f91868e83de9db70238dadfd0d80ca
### Keybase proof
I hereby claim:
* I am sandipb on github.
* I am sandipb (https://keybase.io/sandipb) on keybase.
* I have a public key ASC4KMgsBE9a3n9l9GI0InNtbh-SzM49e_m3sNt7jlAY4Qo
To claim this, I am signing this object:
@sandipb
sandipb / .bashrc
Last active October 11, 2018 22:31
Bashrc to keep a consistent tmux ssh-agent environment
View .bashrc
SOCK="/tmp/ssh-agent-$USER-screen"
SOCKPTR="$(readlink -f $SOCK 2> /dev/null)"
if [[ -z $SOCKPTR ]] || [[ ! -S $SOCKPTR ]]
then
echo -e "\e[31m\e[1mNo valid current tmux ssh-agent link\e[0m"
if [[ -n $SSH_AUTH_SOCK ]] && [[ -S $SSH_AUTH_SOCK ]]
then
rm -f $SOCK
@sandipb
sandipb / test.py
Last active June 11, 2019 23:59
ujson repr trips up json dumps
View test.py
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
sandipb / benchmark_load.py
Created June 12, 2019 00:32
Benchmarking json loading across json and ujson (precision floats and normal)
View benchmark_load.py
import json
import ujson
from timeit import repeat
def decode_json(data):
json.loads(data)
def decode_ujson(data, precise=False):
@sandipb
sandipb / newcert.sh
Created June 21, 2020 11:37
Bash script to generate new server certificates and private key, for the OpenSSL Certificate Authority guide by Jamie
View newcert.sh
#!/bin/bash
# set -x
set -e
cd $(dirname $0)
# The path to the homebrew install on mac. Change to point to your own installation
OPENSSL="/usr/local/Cellar/openssl@1.1/1.1.1g/bin/openssl"
NAME=${1:?Need a hostname for generating certs}
DAYS=375
export SAN="DNS:$NAME"
@sandipb
sandipb / Description.md
Last active August 5, 2020 10:35
Example code to use the Golang httprouter library
@sandipb
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
vars:
kernel_does_not_match: "{{ (ansible_distribution == 'Ubuntu') and ( ansible_kernel != '5.4.0-86-generic') }}"
output_path_local: /tmp/host_kernels
tasks:
- block:
- name: Add matching host to file
@sandipb
sandipb / README.md
Last active May 5, 2022 02:46
Fix cups-pdf not printing PDFs with restrictions
View README.md