This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * A recursive function that applies a callback to nodes in a tree (may include Maps and Arrays). | |
| * @param {*} tree the tree to walk | |
| * @param {walkTreeCb} callback function to apply to nodes that pass the filter function, passed a node, index, and depth. Return true to walk a node that matches the filter. | |
| * @param {walkTreeFilterFunc=} filter a filter function to apply. If not specified will callback for leaf nodes only (not Maps or Arrays). Return true to apply callback. | |
| * @param {number=} i index into array or -1 if parent is an object. Not normally specified in initial call | |
| * @param {number=} d the depth. Not normally specified in initial call | |
| * @param {[]=} k list of ancestor keys. Not normally specified in initaial call | |
| * @param {[]=} a list of ancestor objects. Not normall specified in initial call | |
| * @param {boolean=} walkCyclic indicates cyclic references should be walked. Callback must handle short circuiting by return false. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http') | |
| const https = require('https') | |
| async function fetch(url, options={rejectUnauthorized: false}, timeout=3000, log=true) { | |
| await new Promise((resolve, reject) => { | |
| const req = (/^https/.test(url) ? https : http) | |
| .get(url, options, res => { | |
| let data = '' | |
| res.on('data', chunk => data+=chunk) | |
| res.on('end', () => {log && console.log(data); resolve(data)}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| tmp=$(mktemp -d) | |
| trap "{ rm -rf $tmp; }" EXIT | |
| # ensure we were given two command line arguments | |
| if [[ $# -ne 2 ]]; then | |
| echo 'usage: vault-cp SOURCE DEST' >&2 | |
| exit 1 | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Semantic UI has these classes, however they're only applicable to*/ | |
| /* grids, containers, rows and columns.*/ | |
| /* plus, there isn't any `mobile hidden`, `X hidden` class.*/ | |
| /* this snippet is using the same class names and same approach*/ | |
| /* plus a bit more but to all elements.*/ | |
| /* see https://github.com/Semantic-Org/Semantic-UI/issues/1114*/ | |
| /* Portrait */ | |
| @media only screen and (max-width: 414px) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import com.fasterxml.jackson.databind.ObjectMapper; | |
| import org.junit.Test; | |
| import java.io.IOException; | |
| import java.util.Map; | |
| import static org.junit.Assert.*; | |
| public class FlattenerTest { | |
| @Test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.HashMap; | |
| import java.util.List; | |
| import java.util.Map; | |
| import java.util.Vector; | |
| /** | |
| * Flattens a Map | |
| */ | |
| public class Flattener { | |
| static public void process(Map<String, Object> target) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # get version info from git (look for tag like 'v1.0') | |
| GIT_VERSION = $(shell git describe --match "v[0-9]*") | |
| GIT_BUILD = $(shell git describe --match "v[0-9]*" --long --dirty) | |
| GIT_COMMIT = $(shell git rev-parse --short HEAD) | |
| GIT_COMMIT_LONG = $(shell git rev-parse HEAD) | |
| define VERSION_BODY | |
| # this file generated by build process | |
| { | |
| "version": "${GIT_VERSION}", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // UUID RFC 4122 Version 4 (random) | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <time.h> | |
| | |
| void random_chars(char buffer[], int len) { | |
| for (int i = 0; i < len; i++) { | |
| sprintf(buffer + i, "%X", rand() % 16); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Displays progress (to stderr) by counting lines from stdin. | |
| # | |
| # Usage: <command> | progress.sh <expected-line-count> > <file> | |
| # | |
| total=$(( ${1:-0} )) | |
| number=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var express = require('express') | |
| var mongoskin = require('mongoskin') | |
| var ObjectID = require('mongodb').ObjectID | |
| var query2m = require('query-to-mongo') | |
| // attach db to the router | |
| var db = mongoskin.db('mongodb://localhost:27017/mydb', {safe: true}) | |
| var router = express.Router() | |
| router.db = db | |
| router.use(function (req, res, next) { |