Skip to content

Instantly share code, notes, and snippets.

💻
Working on my own projects

Sal Rahman shovon

💻
Working on my own projects
Block or report user

Report or block shovon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@shovon
shovon / marshal_json_omit_empty.go
Last active Jul 28, 2019
`IsZero` is potentially a method that can be called in order to determine if an instance of a struct is a "zero value". json.Marshal, however, does not yet implement this, and so, this is a solution to the problem, for now
View marshal_json_omit_empty.go
package lib
import (
"encoding/json"
"reflect"
"strings"
)
// IsZeroer implement this if you want some special definition of "zero"
type IsZeroer interface {
@shovon
shovon / monad.go
Last active Jul 26, 2019
Some initial work on monads in Golang
View monad.go
package monad
type ThenCallback func(interface{}) (Thenable, error)
type Thenable interface {
Then(ThenCallback) Thenable
Unwrap() interface{}
}
type Error struct {
@shovon
shovon / selects-to-checkboxes.js
Created Jul 17, 2019
Convert multi-select to checkboxes
View selects-to-checkboxes.js
const form = document.getElementById('form');
const multiSelects = [...form.querySelectorAll('select')]
.filter(el => el.multiple);
function *indexedIteration(iterable) {
let count = 0;
for (const item of iterable) {
yield [ item, count ];
count++;
View README.md

Linked List with Iterator

An example of flattening a linked list with generators.

Usage

const LinkedList = require('./linked-list');

const list = new LinkedList();
View README.md

Iterable Binary Search Tree

Iterators are so useful, that it has now become one of JavaScript's core features. Generators were devised in order to facilitate the creation of iterators. Better yet, with generators, you can nest iterators, and yield a "flattened" result.

The binary search tree is a classic example of where "nested" iterators will be useful.

Usage

const BinarySearchTree = require('./bst.js');
View README.md

Iterable Binary Search Tree

Iterators are so useful, that it has now become one of JavaScript's core features. Generators were devised in order to facilitate the creation of iterators. Better yet, with generators, you can nest iterators, and yield a "flattened" result.

The binary search tree is a classic example of where "nested" iterators will be useful.

Usage

const BinarySearchTree = require('./bst.js');
View README.md

Iterable Binary Search Tree

Iterators are so useful, that it has now become one of JavaScript's core features. Generators were devised in order to facilitate the creation of iterators. Better yet, with generators, you can nest iterators, and yield a "flattened" result.

The binary search tree is a classic example of where "nested" iterators will be useful.

Usage

const BinarySearchTree = require('./bst.js');
@shovon
shovon / README.md
Last active Apr 8, 2019
Left-leaning red-black tree
View README.md

Left-Leaning Red-Black Tree

This is a TypeScript implementation of the Left-Leaning Red-Black Tree.

Usage

import LLRBTree from './llrbtree'

const tree = new LLRBTree((a: number, b: number) => a - b);
View README.md

JavaScript is in no way immune from race conditions.

With JavaScript's most common use case being web application (both front-end and back-end), input and output are therefore not synchronous. Hence the need devise synchronization paradigmes. Transactional integrity, for example, will greatly benefit from any such exercise.

Below is an example usage of a createMutex function that was written in the aim of introducing a primitive similar to mutex locks to JavaScript.

Usage

const { createMutexLock } = require('./mutex');
@shovon
shovon / README.md
Last active Jan 20, 2019
Redux and react-redux compatible library
View README.md

Usage

// App.js

import React from "react";
import { connect } from "./state-manager-react";

const App = props => (
  <div>
You can’t perform that action at this time.