Skip to content

Instantly share code, notes, and snippets.

View paambaati's full-sized avatar
🏠

GP paambaati

🏠
View GitHub Profile
@paambaati
paambaati / 2-HOW-TO-UNDO.md
Last active June 26, 2023 13:29
Designing an Undo system

Designing an Undo system on the backend (v2)

Updates to implementation details based on today's call –

  1. On an update call, make the client send a "snapshot" of the current record, along with the incoming UPDATE payload and save these to cache. Let's call this v1.

  2. Generate the UPDATE query, execute it, and return the updated payload as usual, along with a unique undo_id. Additionally, save these to cache as well. Let's call this v2.

  3. Now if the API consumer needs an undo, they need to send the undo_id, with which we should be able to look up both the v1 record, the v2 record, do a diff and execute a new UPDATE query that rolls back v2 to v1.

@paambaati
paambaati / Dockerfile
Last active June 22, 2023 05:34
Simple Go server that only prints version as response, a Dockerfile to quickly deploy it, and a k6 script that tests it
FROM golang:alpine AS builder
# Install git.
# Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache git
WORKDIR $GOPATH/src/vserver/
COPY . .
# Fetch dependencies.
# Using go get.
RUN go get -d -v
@paambaati
paambaati / commands.sh
Created June 15, 2023 10:26
Debug git for semantic-release
#DEBUG
git notes --ref semantic-release list
# REFER: https://github.com/semantic-release/semantic-release/blob/master/docs/support/troubleshooting.md#release-not-found-release-branch-after-git-push---force
git tag --delete v4.0.0
git push --delete origin v4.0.0
git tag v4.0.0 cdbb31e9cece505753becbfccc7ab64665a4cca5 # Commit that created the release
git notes --ref semantic-release add -f -m '{"channels":[null]}' v4.0.0
git push --force origin refs/notes/semantic-release
@paambaati
paambaati / parse.ts
Created June 15, 2023 10:21
Parse CSV as a stream in Node.js
import { createReadStream } from 'fs';
import { NODE_STREAM_INPUT, parse } from 'papaparse';
(async () => {
const csvStream = createReadStream('machine-readable-business-employment-data-mar-2023-quarter.csv');
const parseStream = parse(NODE_STREAM_INPUT);
csvStream.pipe(parseStream);
const data: Array<Array<string>> = [];
parseStream.on('data', (chunk: Array<string>) => {
data.push(chunk);
@paambaati
paambaati / got.js
Last active March 1, 2023 00:18
Got with HTTP2 support (ALPN negotiation) + Connect settings overrides
const {extend: gotExtend} = require('got');
const http2 = require('http2-wrapper');
const resolveALPN = require('resolve-alpn');
// Taken from https://github.com/nodejs/node/blob/d4c91f28148af8a6c1a95392e5c88cb93d4b61c6/lib/_http_agent.js
//
// throws
// tls.connect({host: 'httpbin.org', port: 443});
//
// doesn't throw
@paambaati
paambaati / PDFtoHTML.scala
Created December 19, 2018 11:03
Extracting HTML from PDFs
package me
import java.io.{File, FileInputStream}
import org.apache.pdfbox.pdmodel.PDDocument
import org.apache.pdfbox.tools.PDFText2HTML
object PDFtoHTML {
def main(args: Array[String]): Unit = {
val stream = new FileInputStream(new File("/Users/me/Downloads/example.pdf"))
@paambaati
paambaati / localstorage_logout_sync.tsx
Last active July 28, 2022 03:33
Logging out of all tabs when logout occurs on 1 tab
// Your main component.
const MyComponentWrapper = (props) => {
// Watch changes to local storage, and if we logout in 1 tab,
// logout in every other tab.
const syncLogout = (event: StorageEvent): void => {
if (event.key === 'logout') {
Router.push('/login');
}
};
@paambaati
paambaati / launch.js
Last active May 5, 2022 05:35
Debug mocha tests using Visual Studio Code
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Run app.js",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
@paambaati
paambaati / README.md
Last active November 24, 2021 06:06
Generate yarn resolutions for audit-ci fixes

How to use this

node auditResolutions.js

This will print some output that looks like this –

{"css-select@npm:2.1.0/nth-check":"&gt;=2.0.1"}
@paambaati
paambaati / upload_demo_html.html
Last active March 28, 2021 14:55
Uploading files using NodeJS and Express 4
<html>
<body>
<form action="/upload" enctype="multipart/form-data" method="post">
<input type="text" name="title">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
</body>
</html>