Skip to content

Instantly share code, notes, and snippets.

View amsourav's full-sized avatar
🎯
Focusing

sourav sarkar amsourav

🎯
Focusing
  • 12:26 (UTC +05:30)
View GitHub Profile
@amsourav
amsourav / replace.py
Created March 24, 2025 08:23
Replace Text in PDF
import re
import argparse
import os
import pikepdf
def replace_text_in_content_stream(content, search_text, replacement_text):
"""
Replace text in PDF content stream while preserving formatting.
Args:
@amsourav
amsourav / interpolate.js
Created August 11, 2024 16:33
Code Interpolation
function interpolateCodeSnippets(array) {
// Create a map for quick lookup by key
const snippetsMap = array.reduce((acc, item) => {
acc[item.key] = item.value;
return acc;
}, {});
// Helper function to interpolate a single snippet
function interpolate(snippet) {
// Regular expression to find all slots
@amsourav
amsourav / useEffectDebugger.js
Created July 2, 2024 20:11 — forked from markselby9/useEffectDebugger.js
A `useEffectDebugger` hook to debug which dependency changed causing `useEffect` hook to fire
// a code snippet living in a component
// source: https://stackoverflow.com/a/59843241/3600510
const usePrevious = (value, initialValue) => {
const ref = useRef(initialValue);
useEffect(() => {
ref.current = value;
});
return ref.current;
};
const useEffectDebugger = (effectHook, dependencies, dependencyNames = []) => {

Keybase proof

I hereby claim:

  • I am amsourav on github.
  • I am amsourav (https://keybase.io/amsourav) on keybase.
  • I have a public key ASDtRk_th3uYVWSAG5lGK4gnlDbK88UZggGW-2bFv72GTwo

To claim this, I am signing this object:

@amsourav
amsourav / index.md
Created October 26, 2020 05:27
interview preparation
@amsourav
amsourav / enzyme_render_diffs.md
Created June 23, 2020 09:47 — forked from fokusferit/enzyme_render_diffs.md
Difference between Shallow, Mount and render of Enzyme

Shallow

Real unit test (isolation, no children render)

Simple shallow

Calls:

  • constructor
  • render
@amsourav
amsourav / awc-ecs-access-to-aws-efs.md
Created December 17, 2018 09:17 — forked from duluca/awc-ecs-access-to-aws-efs.md
Step-by-step Instructions to Setup an AWS ECS Cluster

Configuring AWS ECS to have access to AWS EFS

If you would like to persist data from your ECS containers, i.e. hosting databases like MySQL or MongoDB with Docker, you need to ensure that you can mount the data directory of the database in the container to volume that's not going to dissappear when your container or worse yet, the EC2 instance that hosts your containers, is restarted or scaled up or down for any reason.

Don't know how to create your own AWS ECS Cluster? Go here!

New Cluster

Sadly the EC2 provisioning process doesn't allow you to configure EFS during the initial config. After your create your cluster, follow the guide below.

New Task Definition for Web App

If you're using an Alpine-based Node server like duluca/minimal-node-web-server follow this guide:

@amsourav
amsourav / 0xe43D1e3236bf3E31e5CE31284d8BCbE6Ad1a893B
Created October 16, 2017 04:24
0xe43D1e3236bf3E31e5CE31284d8BCbE6Ad1a893B
0xe43D1e3236bf3E31e5CE31284d8BCbE6Ad1a893B

Keybase proof

I hereby claim:

  • I am amsourav on github.
  • I am amsourav (https://keybase.io/amsourav) on keybase.
  • I have a public key ASC3h89j2ktJ0dhvHQFG9kclFUQ6VbdSuNibi-v0hNOpWwo

To claim this, I am signing this object:

{"swagger":"2.0","info":{"description":"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.","version":"1.0.0","title":"Swagger Petstore","termsOfService":"http://swagger.io/terms/","contact":{"email":"apiteam@swagger.io"},"license":{"name":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}},"host":"petstore.swagger.io","basePath":"/v2","tags":[{"name":"pet","description":"Everything about your Pets","externalDocs":{"description":"Find out more","url":"http://swagger.io"}},{"name":"store","description":"Access to Petstore orders"},{"name":"user","description":"Operations about user","externalDocs":{"description":"Find out more about our store","url":"http://swagger.io"}}],"schemes":["http"],"paths":{"/pet":{"post":{"tags":["pet"],"summary":"Add a new pet to the store","descri