Skip to content

Instantly share code, notes, and snippets.

@alterx
Last active April 11, 2021 21:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alterx/4be465d63fc23e37f95639b0b8ea1739 to your computer and use it in GitHub Desktop.
Save alterx/4be465d63fc23e37f95639b0b8ea1739 to your computer and use it in GitHub Desktop.
GunDB useful resources
// Dletta has implemented a depth-first (and sort of breadth-first) search algorithm for gun graphs.
var stack;
var nodes;
var edges;
var start;
var u;
var label;
var opt = true;
label = 'label';
start = 'startSould';
stack = [];
nodes = new Map();
edges = new Map();
start = await root.get(start).promOnce();
nodes.set(start.key, {id:start.key, label:start.data.label, data:start.data});
u = start;
stack.push(u);
do{
while(!exhausted(u.data, edges)){
// release control on each loop for ui
await delay(20); //play with this value
var edge = exhausted(u.data, edges, true);
var v = await root.get(edge).promOnce();
nodes.set(v.key, {id:v.key, label:v.data.label, data:v.data});
edges.set(u.key+v.key, {source:u.key, target:v.key});
stack.push(v);
}
while(!(stack.length==0)){
await delay(20);
var y = stack.shift();
if(!exhausted(y.data,edges)){
stack.push(y)
u = y;
break;
}
}
}while(!(stack.length==0))
console.log(nodes, edges);
function exhausted(node,edges,opt) {
var soul = Gun.node.soul(node);
var arr = Object.keys(node);
var i = 1;
var l = arr.length;
for(;i<l;i++){
if(typeof(node[arr[i]]) == 'object' && node[arr[i]] != null){
if(!edges.has(soul+node[arr[i]]['#'])){
var temp = node[arr[i]]['#'];
break;
}
}
}
if(!opt) {
if(temp){
return false;
} else {
return true;
}
} else {
if(temp){
return temp;
}
}
};
function transformMap (map) {
var array = Array.from(map);
var result = [];
var i =0;
var l = array.length;
for(;i<l;i++){
result.push(array[i][1])
}
return result;
}
function delay(ms) {
return new Promise((res, rej)=>{
setTimeout(res, ms);
})
}
});

Gun user-space

User-space and public graph get/set with signing and encryption

https://gist.github.com/jabis/a3b7d5b475ef23fb859d3acabe9325cb

GunDB group permissions example. Restrict reads and/or writes.

https://gist.github.com/ThinkingJoules/6da18221dd7ec39058c1f9bfaff392e3

Video conference Gun

https://github.com/meething/webrtc-gun

Gun TODO list tutorial

https://github.com/thrownness/decentralized-todo-app

Gun Synclist

If you have a list with a lot of items you don't want to rebuild your DOM on every change. Instead you only need to change the changed item.

https://github.com/Stefdv/gun-synclist

Gun Svelte example

https://github.com/RadGade/Gun-Svelte https://svelte.dev/repl/3c87b6cae4da4382b02d85c961490719?version=3.18.1

Bullet catcher

https://github.com/zrrrzzt/bullet-catcher

Gun tag

https://github.com/Stefdv/gun-tag

Gun Schema

https://github.com/gundb/gun-schema

RWperm

https://github.com/Dletta/rwperm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment