Skip to content

Instantly share code, notes, and snippets.

View paambaati's full-sized avatar

GP paambaati

View GitHub Profile
paambaati /
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 / 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 /
Created June 15, 2023 10:26
Debug git for semantic-release
git notes --ref semantic-release list
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 / 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);
const data: Array<Array<string>> = [];
parseStream.on('data', (chunk: Array<string>) => {
paambaati /
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 –

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') {
paambaati / select.tsx
Created April 12, 2020 10:40
react-select + react-hook-form
import { forwardRef } from 'react';
import Select from 'react-select';
import { Controller } from 'react-hook-form';
import type { RefObject } from 'react';
import type { Props as ReactSelectProps } from 'react-select';
const Select = forwardRef(
(props: SelectProps, ref: RefObject<HTMLSelectElement>) => {
return (
yarn run v1.17.3
$ ts-node src/debug.ts
D0908 08:17:51.870543000 4400821696] Using native dns resolver
I0908 08:17:51.870996000 4400821696] Spawn timer thread
I0908 08:17:51.871014000 4400821696] grpc_init(void)
I0908 08:17:51.871060000 123145562341376] timers not checked: expect another thread to
I0908 08:17:51.871069000 123145562341376] sleep until kicked
I0908 08:17:51.871329000 4400821696] grpc_completion_queue_create_internal(completion_type=0, polling_type=0)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
paambaati /
Last active February 20, 2019 04:22
Handy script to help migrate all Mesos Marathon apps from 1 cluster to another. Can use either a Marathon URI or a local file location for both source & destination sinks. Works on both Python2 & Python3.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
from os import environ
from json import load, loads, dumps
from urlparse import urlparse
from urllib.request import urlopen, Request
from urllib.error import HTTPError