Skip to content

Instantly share code, notes, and snippets.

import io
import nbt # sudo python3 -m pip install NBT
import os
class BitReader:
def __init__(self, data, size):
self.data = data
self.size = size
@kaustubh-karkare
kaustubh-karkare / promise.js
Last active August 25, 2019 00:41
Educational reimplementation.
class Promise2 {
PENDING = 0;
FULFILLED = 1;
REJECTED = 2;
static resolve(value) {
return new Promise2((resolve, reject) => resolve(value));
}
static reject(value) {
const React = {};
/**
* ReactElements are lightweight objects which contain information necessary to
* create the equivalent DOM nodes. All JSX tags are transformed into functions
* that return instances of this class.
* Note that the decision to actual create those nodes and insert them into the
* document hasn't been made yet: it is possible that that might never happen.
*/
#!/usr/bin/env node
var fs = require("fs"), path = require("path");
var run = function(root,start){
var fs = require("fs"), path = require("path"); // intentionally redefined
var ext = ".js", index = "index"+ext, pkg = "package.json";
var locate = function(root,name){
var p = name.split(path.sep);
// all relative module references must be inside the specified directory
@kaustubh-karkare
kaustubh-karkare / augmented-json-serialization-functions.js
Last active May 3, 2018 13:15
Augmented Versions of the `JSON.stringify` & `JSON.parse` functions.
/*
Since the default implementations of the `JSON.stringify` and `JSON.parse` functions do not
support serialization of `Infinity`, `-Infinity`, `NaN`, RegExp instances or circular references
in objects, the following functions can be used when such support is required.
The value `undefined` has been left out given how objects already return the same when the
user tries to access a non-existent key. While there are situations where the presence of the
key itself matters, they are infrequent enough not to have warranted support.