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 / SketchSystems.spec
Last active June 19, 2023 16:23
MR Mystery Box
MR Mystery Box
reveal -> MR Character
MR Character
equip ->
// 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 / 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;
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 / 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;
}
@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 / graph.js
Last active February 14, 2024 23:29
JavaScript implementation of Graph Data Structure
// Implement a Graph
// basic operations:
// - add vertex (node)
// - add edge (node -> node)
function GraphNode(val) {
this.val = val;
this.edges = {};
}
@tpae
tpae / queue.js
Last active August 13, 2021 07:04
JavaScript implementation of Queue Data Structure
// Implement a Queue using LinkedLists
// we know that queue is LIFO
// operations: enqueue, dequeue
function QueueNode(val) {
this.val = val;
this.next = null;
}
function Queue() {
@tpae
tpae / stack.js
Last active November 10, 2016 05:25
JavaScript implementation of Stack Data Structure
// Implement a stack using LinkedLists.
// Operations:
// -> push
// -> pop
// -> peek
function StackNode(val) {
this.val = val;
this.next = null;
@tpae
tpae / minHeap.js
Last active April 8, 2024 14:14
JavaScript implementation of Min Heap Data Structure
// Implement a min heap:
// -> insert, extract_min
// property:
// - elements are in ascending order
// - complete binary tree (node is smaller than it’s children)
// - root is the most minimum
// - insert takes O(logn) time
// - insert to the bottom right