Skip to content

Instantly share code, notes, and snippets.

View dexterous's full-sized avatar

Saager Mhatre dexterous

View GitHub Profile
@dexterous
dexterous / TestHarnessHTTPServer.groovy
Last active October 21, 2020 23:14
Quick and dirty HTTP server for functional tests that presents itself as a Future.
import java.util.concurrent.CompletableFuture
import java.util.concurrent.TimeUnit
import java.util.concurrent.CancellationException
import java.util.concurrent.TimeoutException
import java.net.InetSocketAddress
import com.sun.net.httpserver.HttpServer
import com.sun.net.httpserver.HttpHandler
import com.sun.net.httpserver.HttpExchange
(defn sum [coll]
(apply + coll))
(defn squares [coll]
(map #(* % %) coll))
(def first-n take)
(defn integers []
(iterate inc 1))
@dexterous
dexterous / fizzbuzz
Created October 7, 2017 04:05
A succinct bash fizzbuzz
#!/bin/bash -e
#set -o xtrace
if [[ $# -lt 1 ]]; then
echo '
Usage: fizzbuzz upto
upto: The number upto which to count
'
@dexterous
dexterous / an-american-bakt.md
Last active March 15, 2017 05:12
An American Bakt[sic]?? -Jason K

As posted on Facebook; and subsequently deleted

As an American and a self confessed Indophile, I had a lot of insights I gleaned while traversing the length and breadth of the country. Incidentally I take care of funded projects and this exposes me to a interactions with the poor and ultra poor of the country. Hopefully I will debunk a few myths about India, which my North American colleagues should know, along with some Indians who will hopefully read this post:

  1. Like it or leave it, the hinterland of India is firmly behind Modi. They don't give a rat's ass if you call them his followers, or "bakts" as I have heard. For the first time they have a leader and a party that has gone through almost 3 years without a single financial scam against their name. For a country used to spectacular monetary frauds and a silent PM who took plausible deniability to laughable proportions, this is a great and welcome change
  2. Muslim don't hate Modi. Educated intelligent non Muslims (read Hindus) hate him more! Simply
<html>
<body>
<form method="GET" action="/file" target="_blank">
<input name="filename" type="text" />
<input name="submit" type="submit" />
</form>
</body>
</html>
@dexterous
dexterous / metaclass_usage.py
Last active January 22, 2017 22:47
Sample Python Metaclass usage
from __future__ import print_function
from itertools import ifilter
import re
def snake_case(string):
return re.sub('[A-Z]+', lambda m: '_' + m.group().lower(), string).lstrip('_')
@dexterous
dexterous / fix-multi
Last active July 19, 2019 19:36
Sed script to fix CSV file with unescaped new lines.
#!/bin/sed -nrf
s_,,,,_,"","","",_g # first we substitute blank fields with quoted blanks for consistency
s_,,,_,"","",_g # first we substitute blank fields with quoted blanks for consistency
s_,,_,"",_g # first we substitute blank fields with quoted blanks for consistency
s_,$_,""_ # then we handle similar blank trailing fields
/^([^"]|",|"")/ { # if the line does not start with " (incomplete line)
x # first swap the previous line [see (*) below] into pattern space and this incomplete line into hold space
G # add the above held incomplete like to the pattern separated by \n
@dexterous
dexterous / psql_check.sh
Last active August 15, 2017 18:12
Quick n' dirty script to monitor PostgreSQL connectivity and connect latency and post metrics to AWS Cloudwatch
#!/bin/bash
export PGPASSWORD='password'
IFS=':'
echo ''
date '+%F %T'
for HOST in www.{foo,bar}.com; do
@dexterous
dexterous / prog.py
Last active July 19, 2019 19:28
A quick test to see how the GIL serializes seemingly concurrent operations in Cpython.
#!/usr/bin/python
from __future__ import print_function
import sys
import threading
import Queue
import argparse
@dexterous
dexterous / set-vault-ttl.sh
Created November 4, 2016 18:19
Command to set TTL for Vault logins
vault mount-tune -default-lease-ttl=1800s -max-lease-ttl=1800s auth/ldap