Skip to content

Instantly share code, notes, and snippets.

View alexander-mart's full-sized avatar
💭
☮️

Alexander Mart alexander-mart

💭
☮️
View GitHub Profile
@ggondim
ggondim / BuildTree.ts
Created January 18, 2022 00:03
Build a object tree (parent/children) given an object array of type T, the object ID key (elementKey) and the object parent key (parentKey)
type TreeItem<T> = T & { children: TreeItem<T>[] };
export default function buildTree<T>(array: T[], elementKey: keyof T, parentKey: keyof T): TreeItem<T>[] {
let tree = [] as TreeItem<T>[];
for (let i = 0; i < array.length; i++) {
if (array[i][parentKey]) {
let parent = array.filter(elem => elem[elementKey] === array[i][parentKey]).pop() as TreeItem<T>;
if (!parent['children']) {
parent.children = [];
}
#!/bin/bash
# Connect to TerminusDB and dump all data (RDF-triplets) to local file
# https://gist.github.com/alexander-mart/ff1c896f55e5cc7774e922e3f977961b
# Access the TerminusDB CLI from the Docker Compose:
# https://terminusdb.com/docs/install-terminusdb-as-a-docker-container/#usingthecli
# TerminusDB dump command:
# https://terminusdb.com/docs/terminusdb-cli-commands/#triplesdump