Skip to content

Instantly share code, notes, and snippets.

View rrmhearts's full-sized avatar

Ryan rrmhearts

View GitHub Profile
@rrmhearts
rrmhearts / list_nodes_to_tree.js
Last active July 20, 2020 15:30
Create Tree Structure from list of nodes with parent property
const idMapping = data.reduce((acc, el, i) => {
acc[el.id] = i;
return acc;
}, {});
let root = [];
data.forEach(el => {
// Handle the root element
if (el.parent === null) {
root.push(el);
@rrmhearts
rrmhearts / tree_to_list_nodes.js
Last active July 20, 2020 15:29
Create a flat list of nodes from a nested tree structure.
// nestedTree is a tree structure containing subtrees under "nodes" property. d=1 is the default "depth of the tree"
function flatDeep(arr, d = 1) {
return d > 0 ? arr.reduce((acc, val) => acc.concat(Array.isArray(val.nodes) ? flatDeep(val.nodes, d - 1) : val), [])
: arr.slice();
};
let flat = flatDeep(nestedTree, Infinity);
// Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat
@rrmhearts
rrmhearts / RecoverGrub.md
Created March 31, 2025 19:29
How to repair or update grub from a live cd using chroot.
# --rbind mounts subdirectories that are required.
sudo mount /dev/sda3 /mnt/
sudo mount --rbind /proc/ /mnt/proc/
sudo mount --bind /sys/ /mnt/sys/
sudo mount --rbind /dev/ /mnt/dev/
sudo chroot /mnt/

# Repair grub in /etc/default/grub