Skip to content

Instantly share code, notes, and snippets.

View tpae's full-sized avatar

Terence Pae tpae

  • San Francisco, CA
  • X @tpae
View GitHub Profile
@tpae
tpae / Trie.js
Created November 20, 2016 23:49
Trie.js - super simple JavaScript implementation
// Trie.js - super simple JS implementation
// https://en.wikipedia.org/wiki/Trie
// -----------------------------------------
// we start with the TrieNode
function TrieNode(key) {
// the "key" value will be the character in sequence
this.key = key;
@tpae
tpae / LRUCache.js
Created November 21, 2016 08:16
super simple JavaScript Implementation of LRUCache
// LRUCache.js - super simple JavaScript Implementation
// LRU stands for "Least Recently Used"
// https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
// -----------------------------------------
function LRUNode(key) {
this.key = key;
this.next = this.prev = null;
}
function MergeSort() { }
MergeSort.prototype.sort = function(values) {
if (values.length < 2) {
return values;
}
var mid = Math.floor(values.length/2);
var left = this.sort(values.slice(0, mid));
var right = this.sort(values.slice(mid, values.length));
@tpae
tpae / OfferManager.sol
Last active March 7, 2021 16:24
Library to help manage multiple offer bids for tokens
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.7.0;
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/EnumerableSet.sol";
library OfferManager {
using EnumerableSet for EnumerableSet.UintSet;
using EnumerableSet for EnumerableSet.AddressSet;
using Counters for Counters.Counter;
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@tpae
tpae / SketchSystems.spec
Last active June 19, 2023 16:23
MR Mystery Box
MR Mystery Box
reveal -> MR Character
MR Character
equip ->