Skip to content

Instantly share code, notes, and snippets.

View saswata-dutta's full-sized avatar
💭
I may be slow to respond.

Saswata Dutta saswata-dutta

💭
I may be slow to respond.
View GitHub Profile
@saswata-dutta
saswata-dutta / native_di.scala
Created December 10, 2019 10:41
using scala trait and object for DI
// https://www.michaelpollmeier.com/2014/06/29/simple-dependency-injection-scala
// define
trait MyService {
def foo = 42
}
// instantiate
object MyService extends MyService
#!/usr/bin/env bash
# set -xv
user=$1
pass=$2
# get token
pass_md5="$(echo -n "$pass" | md5)"
pass_sha512="$(echo -n "${pass}"'ewor88493GVHBMe@' | sha512sum | cut -f1 -d' ')"
@saswata-dutta
saswata-dutta / Search my gists.md
Created November 10, 2019 18:46 — forked from santisbon/Search my gists.md
How to search gists

Enter this in the search box along with your search terms:

Get all gists from the user santisbon.
user:santisbon

Find all gists with a .yml extension.
extension:yml

Find all gists with HTML files. language:html

@saswata-dutta
saswata-dutta / bing_maps_waypoints.py
Created October 29, 2019 13:08
read waypoints from file and invoke bing maps route api
#!/usr/bin/env python3
import pandas as pd
import requests
import json
import sys
base_url='https://dev.virtualearth.net'
api='REST/v1/Routes/Truck'
@saswata-dutta
saswata-dutta / cumulative_pandas_haversine.py
Created October 29, 2019 10:29
cumulative haversion on lat lon of previous row
from datetime import datetime
import time
def as_epoch(row):
dt = datetime.strptime(row['gps_timestamp'], '%Y-%m-%d %H:%M:%S%z')
return int(time.mktime(dt.timetuple()))
df['epoch'] = df.apply (lambda row: as_epoch(row), axis=1)
df = df.drop('gps_timestamp', axis=1)
df = df.sort_values('epoch')
@saswata-dutta
saswata-dutta / elk_search.sh
Last active October 17, 2019 14:58
cli call and parse elk logs
#!/usr/bin/env bash
index="$1"
pattern="$2"
size="$3"
query="http://ek-elasticsearch.rivigo.com/${index}/_doc/_search?q=stackTrace:${pattern}&_source=stackTrace&scroll=10m&size=${size}&filter_path=hits.hits._source.stackTrace"
curl -s -XGET "${query}" | jq ".hits.hits[]._source.stackTrace" -r
// cat payload.json | openssl sha256 -hmac 'secret'
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
val payload = scala.io.Source.fromFile("payload.json").mkString
val secret = "secret"
val sha256_HMAC = Mac.getInstance("HmacSHA256")
val secret_key = new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256");
sha256_HMAC.init(secret_key)
@saswata-dutta
saswata-dutta / Tree.scala
Created September 26, 2019 06:57 — forked from dholbrook/Tree.scala
Scala binary tree
/**
* D Holbrook
*
* Code Club: PO1
*
* (*) Define a binary tree data structure and related fundamental operations.
*
* Use whichever language features are the best fit (this will depend on the language you have selected). The following operations should be supported:
*
* Constructors
# Enter your code here. Read input from STDIN. Print output to STDOUT
from collections import defaultdict
from copy import deepcopy
def get_adj_list_and_zero_degree(no_of_nodes, all_edges):
all_node_nos = {i for i in range(no_of_nodes)}
adj_mat = defaultdict(list)
in_nodes = set()
for e in all_edges:
adj_mat[e[0]].append(e[1])
#!/usr/bin/env python
import boto3
rds = boto3.client('rds', region_name='ap-south-1')
dbs = rds.describe_db_instances()
def get_tags_for_db(db):
instance_arn = db['DBInstanceArn']
instance_tags = rds.list_tags_for_resource(ResourceName=instance_arn)