Skip to content

Instantly share code, notes, and snippets.

View shovon's full-sized avatar
💻
Working on my own projects

Sal Rahman shovon

💻
Working on my own projects
View GitHub Profile
export type Links = { [key: string]: Link };
export type StatusCode =
| "400"
| "401"
| "402"
| "403"
| "404"
| "405"
| "406"
@shovon
shovon / README.md
Last active February 23, 2021 15:21

console.debug debugger helper

A simple module for helping you write debugger outputs. Makes debug outputs look neat and organized.

Usage

Copy and paste the index.ts file to some debug.ts file.

import createDebugger from './debug';
@shovon
shovon / README.md
Last active December 7, 2020 21:51
Implementation of writing a WAV file.

Usage

go run main.go
# Result should be in example.wav.
#
# Listen to the result using whatever audio player that supports WAV
@shovon
shovon / webpack.config.js
Created September 22, 2020 15:10
Webpack config with web workers directly embedded in the JavaScript
const path = require("path");
module.exports = {
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
libraryTarget: "commonjs",
},
devtool: "source-map",
@shovon
shovon / event-emitter.js
Created September 14, 2020 06:07
A re-implementation of EventEmitter.
/**
* This is a class that is analogous to the DOM's `EventTarget` API.
*
* It is the class for adding event listeners, and emitting events.
*
* Usage:
*
* const emitter = new EventEmitter()
*
* emitter.addEventListener('foo', (value) => {
@shovon
shovon / README.md
Last active September 12, 2020 06:59
My attempt at implementing the Observable proposal, as proposed by the TC39

Attempt at Implementing TC39's Observable Proposal

This was my attempt at implementing the TC39's observable proposal.

Unfortunately, way too many tests fail.

If you want, you can give it a try to have all the tests pass.

Running the Tests

@shovon
shovon / async.js
Last active April 19, 2020 18:02
Some async handler.
// If I don't care about the status code
function fetchJSON(...params) {
return fetch(...params).then(res => res.json());
}
// If I do care about the status code, but don't care about the type of error.
async function fetchJSON(...params) {
const res = await fetch(...params);
if (res.status >= 400) {
throw new Error(res.statusText);
@shovon
shovon / README.md
Created December 15, 2019 03:48
Benchmark of arrays vs linked lists.

Benchmark of Arrays vs Linked Lists

Running the benchmark:

go test -bench=.

This is the result that I got on my i7 2018 MacBook Pro.

@shovon
shovon / README.md
Created December 9, 2019 05:21
An implementation of a Trie data structure.

Usage

A trie is a key-value pair data structure, that allows you to store a value, by associating it with some string value. If you happen to know what that string value is, then you can retrieve the original value associated with the string.

If the string value is not associated to any value, then a null is returned.

As opposed to an associative array, tries actually save memory, by not storing redundant character prefixes of strings.

import Trie from './trie';
@shovon
shovon / http-tcp.go
Last active August 28, 2019 00:42
A dumb little HTTP server that works on top of TCP.
package main
import (
"bufio"
"errors"
"fmt"
"io"
"log"
"net"
"net/http"