Skip to content

Instantly share code, notes, and snippets.

@malisetti
malisetti / transaction.ts
Created Aug 16, 2021
Execute several functions in a transaction
View transaction.ts
export type fn = () => Error | null;
export type tfn = { run: fn, revert: fn };
export const doInTransaction = async (i: tfn[]): Promise<Error | null> => {
const reverts: fn[] = [];
for (const fn of i) {
try {
const err = await fn.run();
if (err) {
throw err;
@malisetti
malisetti / bitmasks.ts
Last active Jun 8, 2021
typescript enum bitmasks
View bitmasks.ts
https://www.typescriptlang.org/play?#code/PTAEGUFMGcAsEMDGCA28C2oC0oAuBPABxkQCcBLQ3UAI3N3XmgGtoBYAKE8gDsBXTAGEASgFUAIqADenUHNCDSkeLkigAvKACMoADy7QABgA0s+cOUATDdr0GtpjvNCjCllWs079oAEyPncUgUSFUbbwMAZkcAX05ORAB7HmhqAEEUFBEJAHkqcmToG2zxADpFZTCAHwUxMot4axqS0td3atqJUqCQ1QBueI4klMSQ0pREgHMACgysurzcApSASgGuIcLqeEzEgHdLReWizQBtFoqPY06yto8AXXXOXtp6E6N1gDNE0lBp4dSoESQM+oB2EwOR0KK2kZjkdFwRSqmkS6ziGwBo0g4ym0wR0DWg0xYwmMzxb1AADIbuUlB4YepGTTLqpCZsRiTceTEVSaXdWRomS1+ZA2Zx8VTNAA-YVuDxPdnQLE4mb4sWK5Wk6bcorUi50gWMzT6yqi9bE7FanW82XtUWC411Vpy1nrIA
// Seshachalam - typescript bitmasks
enum CRUD {
Create = 1 << 0,
Read = 1 << 1,
Update = 1 << 2,
Delete = 1 << 3,
}
@malisetti
malisetti / gist:23e0f1976dfcda3d7188c921b92fc0ed
Created Oct 20, 2019
Letter to my fellow Software Engineers
View gist:23e0f1976dfcda3d7188c921b92fc0ed
I started working in mid 2012 as a software engineer for a multi national services company based in Bangalore as a post graduate from a very famed university from south India which was in 11th position when I started my studies there in the list of top engineering colleges in India. I graduated in 2012. Most of my classes felt like school mostly because of my department. Even in university campus I was not exposed to practical real world usages to sciences be it may any kind science. The internet was not accessible very easily at that time and exposure to online courses was limited to 0. I always dreamt of studying at Stanford some course related to computer science. I had to take work a job than study after 2012. Its not fair to study after getting a master's degree. I shouldn't say this but I was limited by my surroundings, society, everyone in colleges, my family and relatives, mostly everyone I know of. The thing is you have to work and earn somehow after you complete your education. This is true in ideal
@malisetti
malisetti / pl-types.txt
Created Sep 26, 2019
Programming languages types
View pl-types.txt
pl
assembly
binaryDataFormat
xmlFormat
standard
compiler
computingMachine
grammarLanguage
application
ir
View learn_python.txt
Read history of python
How python evolves ? python2 to python3 https://www.python.org/dev/peps/
How python is different from C like languages ?
Can concurrent programs be written in python ? If yes, what are the concurrent models built into the language
When can python be slow ? or what kind of applications cant be written in python ?
How python can use libraries written in other languages, like C and rust ?
Why is python used majorly in scientific computing ? What are the other languages that are alternative to python in scientific computing ?
Understand package management for libraries in python ? Use an external library in a program.
How are the libraries related to SQL databases ? Use sqlite with python
Are complex numbers(imaginary numbers) supported in python standard library?
@malisetti
malisetti / gif-to-images-tar-gz.go
Last active Sep 10, 2019
A simple web server to convert GIF from an url to compressed archive of images
View gif-to-images-tar-gz.go
package main
import (
"archive/tar"
"bytes"
"compress/gzip"
"fmt"
"image/gif"
"image/png"
"io"
@malisetti
malisetti / html-to-text-nltk.go
Created Mar 15, 2019
get text representation of html and do entity extraction
View html-to-text-nltk.go
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"sort"
"strings"
@malisetti
malisetti / lifecolors.go
Last active Dec 28, 2018
string -> color
View lifecolors.go
package main
import (
"bytes"
"flag"
"fmt"
"image"
_ "image/jpeg"
_ "image/png"
"io"
View maxSpan.js
"use strict";
const assert = require("assert");
/**
* Consider the leftmost and righmost appearances of some value in an array. We'll say that the "span" is the number of elements between the two inclusive. A single value has a span of 1. Returns the largest span found in the given array. (Efficiency is not a priority.)
maxSpan([1, 2, 1, 1, 3]) → 4
maxSpan([1, 4, 2, 1, 4, 1, 4]) → 6
maxSpan([1, 4, 2, 1, 4, 4, 4]) → 6
View stringSplosion.js
"use strict";
const assert = require("assert");
(() => {
const inouts = {
Code: "CCoCodCode",
abc: "aababc",
ab: "aab"
};