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
:dependsOn org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.encodeToString
java
-XX:MaxRAM=<real mem sz in bytes, 10% over max-heap ?> -Xmx512m
-XX:+UseCompressedOops -XX:ObjectAlignmentInBytes=8
-XXfullCompaction
-XXtlaSize:1k
-XX:+UseParallelGC
-XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10
-XX:GCTimeRatio=2
-XX:AdaptiveSizePolicyWeight=90
-XXaggressive:opt
import java.util.*;
import java.util.stream.Collectors;
class Main {
static record Record(String asin, String sid, String wid) {}
public static void main(String[] args) {
var m =
Map.ofEntries(
Map.entry("k1", List.of(new Record("a1", "s1", "w1"), new Record("a2", "s1", "w1"))),
@saswata-dutta
saswata-dutta / simple_rest_custom_log.py
Created June 21, 2023 16:52
simple py rest api server with rotating logs
from bottle import Bottle, get, post, run, request, response
from datetime import datetime
from functools import wraps
import logging
from logging.handlers import RotatingFileHandler
logger = logging.getLogger("app")
# set up the logger
case class MyIo[A](unsafeRun : () => A) {
def map[B](f: A => B): MyIo[B] = MyIo(() => f(unsafeRun()))
def flatMap[B](f: A => MyIo[B]): MyIo[B] = MyIo(() => f(unsafeRun()).unsafeRun())
}
val printer = MyIo(() => println("how"))
val doit = printer.flatMap( _ => printer)
val other = printer.map( _ => println("w"))
aws application-autoscaling register-scalable-target --region REGION \
--service-namespace sagemaker \
--resource-id endpoint/ENDPOINT_NAME/variant/VARIANT_NAME \
--scalable-dimension sagemaker:variant:DesiredInstanceCount \
--min-capacity MIN_VALUE \
--max-capacity MAX_VALUE
target_tracking_json='{"TargetValue": SCALING_VALUE, "PredefinedMetricSpecification": {"PredefinedMetricType": "SageMakerVariantInvocationsPerInstance"}}'
echo $target_tracking_json > target_tracking_scaling_policy.json
@saswata-dutta
saswata-dutta / aws_s3_access.js
Created June 14, 2023 04:47
access aws s3 using js sdk v3
import {
S3Client,
PutObjectCommand,
GetObjectAttributesCommand,
GetObjectCommand,
DeleteObjectCommand,
ListObjectsV2Command,
} from "@aws-sdk/client-s3";
@saswata-dutta
saswata-dutta / cloud9.md
Created May 30, 2023 06:17 — forked from jamstooks/cloud9.md
Notes on starting up an AWS Cloud9 Django dev environment with Python3

My AWS Cloud9 Setup for Python/Django and Node

Getting setup

sudo yum -y update

I'm not a big fan of their default bash prompt:

echo "export PS1='[\D{%F %T}]\n\[\e]0;\w\a\]\[\e[32m\]\u:\[\e[33m\]\w\[\e[0m\]\n\$ '" >> ~/.bashrc

source ~/.bashrc

@saswata-dutta
saswata-dutta / aws_lambda_batch_item_fails.js
Created May 23, 2023 08:54
aws lambda batch item fails
console.log('Loading function');
exports.handler = async (event) => {
//console.log('Received event:', JSON.stringify(event, null, 2));
const fails = [];
for (const { messageId, body } of event.Records) {
console.log('SQS message %s: %j', messageId, body);
fails.push(messageId);
}