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 / artillery-config.test.yaml
Created September 11, 2022 18:10 — forked from whitehorse0/artillery-config.test.yaml
Artillery configuration example Load testing, and allow writing custom logic JS functions to be called at certain points during the execution of a scenario.
config:
target: "http://localhost:8000"
http:
timeout: 10 # Responses have to be sent within 10 seconds or the request will be aborted
processor: "./processor.js"
phases:
# Create 100 virtual users every second for 60 seconds
- duration: 60 # seconds
arrivalRate: 100 # virtual users
@saswata-dutta
saswata-dutta / cloudwatch_logs_cli.sh
Created July 31, 2022 16:26
fetch cloudwatch logs
aws logs filter-log-events \
--log-group-name '/aws/lambda/my-lambda' \
--log-stream-name-prefix '2022/07/31/[$LATEST]' \
--start-time 1659247200000 \
--end-time 1659254400000 \
--filter-pattern '"EVENT ::"'
# [--starting-token <value>]
@saswata-dutta
saswata-dutta / str_to_int.md
Last active July 24, 2022 14:55
string to int mapping using md5
bs = hashlib.md5("Apple".encode('utf-8')).digest()
# b'\x9fb\x90\xf4CnZ#Q\xf1.\x03\xb6C<<'

int.from_bytes(bs[:4], 'big', signed=True)
# -1620930316
val oid_info = Seq((1,1), (1, 2), (1, 1), (2, 1), (2, 3), (3, 4), (3, 3), (3, 4)).toDF("oid", "ip")
"""
+---+---+
|oid| ip|
+---+---+
| 1| 1|
| 1| 2|
| 1| 1|
@saswata-dutta
saswata-dutta / cloudwatch_insights_lambda_mem_used.sh
Created July 9, 2022 07:31
Find stats of cloudwatch lambda max mem used per day in logs insights
filter @type = "REPORT"
| fields @maxMemoryUsed/1000000 as MemUsedMb
| stats max(MemUsedMb) by bin(1d)
@saswata-dutta
saswata-dutta / cum_sum_gaps.scala
Last active April 5, 2022 03:05
Spark cumulative sum with gaps
import spark.implicits._
import org.apache.spark.sql.expressions.Window
import org.apache.spark.sql.functions._
import org.apache.spark.sql.types.IntegerType
import org.apache.spark.sql.internal.SQLConf.SHUFFLE_PARTITIONS
// need to set the shuffle partitions correctly based on data sizes and distribution
@saswata-dutta
saswata-dutta / foobar.py
Created March 29, 2022 07:39 — forked from bhtucker/foobar.py
Sharing memory across uwsgi workers
"""
Simple worker showing different worker ids sharing/incrementing the same memory region
uwsgi --http :9090 --wsgi-file foobar.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191 --sharedarea 2
Then just keep refreshing localhost:9090
"""
import uwsgi
INT_ORDS = {48, 49, 50, 51, 52, 53, 54, 55, 56, 57}
create table scores(id smallint primary key, score smallint not null);
CREATE INDEX score_idx ON scores (score);
WITH RECURSIVE
cnt(x) AS (
SELECT 1
UNION ALL
SELECT x+1 FROM cnt
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@saswata-dutta
saswata-dutta / pyrasite-stacktrace-how-to.md
Created September 24, 2021 05:14 — forked from soxofaan/pyrasite-stacktrace-how-to.md
How to get a stack trace from a stuck/hanging python script

How to get a stack trace for each thread in a running Python script

Sometimes a Python script will simply hang forever with no indication of what is going wrong. Perhaps it's polling a service that will never return a value that allows the program to move forward.

Here's a way to see where the program is currently stuck, using pyrasite a tool for injecting code into running Python processes.

Install gdb and pyrasite

Install gdb.