Skip to content

Instantly share code, notes, and snippets.

View greyscaled's full-sized avatar
🕹️

Greg greyscaled

🕹️
  • Hamilton, ON
View GitHub Profile
const R = 26
function Node (value = null) {
this.value = value
this.next = new Array(R)
}
class Trie {
constructor () {
this.root = new Node()
class Trie {
constructor () {
this.root = new Node()
}
put (key = '', val = null) {
this.root = recursiveInsert(this.root, key, val, 0)
}
// ...
const recursiveInsert = (node, key, val, d) => {
if (!node) node = new Node()
if (d === key.length) {
node.value = val
return node
}
let c = Base26.getBase26Digit(key[d])
node.next[c] = recursiveInsert(node.next[c], key, val, d + 1)
return node
}
const collect = (node, pre, pattern, q) => {
if (!node) { return }
let d = pre.length
if (d === pattern.length && node.value) { q.push(pre) }
if (d === pattern.length) { return }
let next
pattern[d] === '.'
? next = '.'
: next = Base26.getBase26Digit(pattern[d])
const Base26 = require('./base26')
/** The Radix of the Trie. In thise case, base 26 */
const R = 26
/**
* An node contains a value and links that point to other nodes.
* @typedef {Object} Node
* @property {any} value
* @property {Array} next
/**
* A set of static methods governing string-to-int conversion
* in base26. In base26, only lowercase alpha chars [a-z]
* are valid and map to an integer range (0, 26]
*/
module.exports = {
/**
* returns the base26 integer corresponding with the provided char. Note
* that by design uppercase chars may be supplied, and are
module.exports = function ({ port }) {
const debug = require('debug')('run__on::server::app.js')
const express = require('express')
const path = require('path')
const helmet = require('helmet')
const RateLimit = require('express-rate-limit')
const { internalError } = require('./middleware')
// Configuration ----------------/
@greyscaled
greyscaled / SlotMachine.java
Last active September 26, 2018 14:05
SlotMachine
import javafx.beans.property.SimpleStringProperty;
/**
* Class representing a transit ticket vending machine. This is an example
* and only demonstrates a single property: selecting a transit route.
*/
public final class SlotMachine {
/**
* ROUTES that tickets can be issued for
@greyscaled
greyscaled / SlotMachineTab.fxml
Created September 26, 2018 14:39
FXML Template for SlotMachine.java
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Text?>
@greyscaled
greyscaled / SlotMachineTabController.java
Created September 26, 2018 14:48
Controller for SlotMachineTab.fxml
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.text.Text;
/**
* FXML Controller class for SlotMachineTab.fxml
*/
public class SlotMachineTabController {
/**
* SlotMachine Model