Skip to content

Instantly share code, notes, and snippets.

@treelite
treelite / traverse-tree-children.js
Created January 14, 2019 08:56
Traverse children from a tree
function traverseChildren(node, fn, paths = []) {
const children = node.children || [];
let i = 0;
for (const child of children) {
const currentPaths = [...paths, i++];
let stop = fn(child, currentPaths);
if (!stop) {
stop = traverseChildren(child, fn, currentPaths);
}
@treelite
treelite / Validator.js
Created October 12, 2016 06:31
Validator for custom data
/**
* @file Validator for custom data
* @author treelite(c.xinle@gmail.com)
*/
const STATE_IDLE = 0;
const STATE_SPLIT = 1;
const STATE_TOKEN = 2;
const STATE_NEWLINE = 3;
@treelite
treelite / installsdk_miwifi.sh
Last active August 29, 2015 14:04
install MiWiFi SDK
#! /bin/bash
BASE_URL="http://bigota.miwifi.com/xiaoqiang/sdk"
EXT_NAME=".zip"
TMP_DIR="tmp"
TOOL_CHAIN="xiaomi_toolchain"
@treelite
treelite / pre-commit.sh
Last active August 29, 2015 13:57
git pre-commit hook
#!/bin/bash
#
# path: .git/hooks/pre-commit
echo "\n\x1B[33mCommit checking ...\x1B[0m\n"
npm test
exitCode=$?
if [ $exitCode -ne 0 ]
@treelite
treelite / nextTick.js
Last active December 29, 2015 04:09
nextTick
/**
* @file nextTick
* @author treelite(c.xinle@gmail.com)
*/
define(function () {
var res;
var Observer;
var callbacks = [];