Skip to content

Instantly share code, notes, and snippets.

View jabis's full-sized avatar

Jabis Sevon jabis

View GitHub Profile
@jabis
jabis / gun3import.js
Created January 29, 2020 17:21 — forked from amark/gun3import.js
This takes the internal functionality of `.put` and RIPS IT OUT, separating it from the chaining API and the event listeners that cause problems - but NOTE, this does not support the chaining API or async behavior! Plus it has a couple extra hidden gems like auto-Array-to-Object conversion and UUID hinting.
function importGUN3 (data, options){
options = options || {};
options.prefix = 'gun/';
if(options.arrays !== false){
options.arrays = true;
data = array2object(data);
}
var drift = options.state || Gun.time.now();
var ctx = {}, at = {};
Gun.ify(data, function(env, cb, map){
@jabis
jabis / GunShareExample
Created January 29, 2020 17:01 — forked from pszabop/GunShareExample
Example of using Gun to share a secret with another user. Includes unit tests.
// alas this generates the warning `user.pair() IS DEPRECATED AND WILL BE DELETED!!!`
//
// put a value shared between two users
// user and this user (classic public key encryption, except that a session
// key is used instead of encrypting the data with the public key.
// analagous to `openssl pkeyutl -derive -inkey key.pem -peerkey pubkey.pem -out secret`
//
// @param: key - the key where the value is stored
// @param: value - the value to store at index key
// @param: otherUser - the info or public key of the other user to share the value with
@jabis
jabis / gun-promises-using-nodejs-tape.js
Last active January 13, 2020 09:42 — forked from pszabop/gun-promises-using-nodejs-tape.js
Gun promises using nodejs and tape
'use strict'
const fs = require('fs');
const tape = require('tape');
const _test = require('tape-promise').default // <---- notice 'default'
const test = _test(tape) // decorate tape
const Gun = require('../gun')
require('../gun/sea')
require('../gun/lib/then.js')
require('../gun/lib/promise.js')
const mkdirp = require('mkdirp');
@jabis
jabis / Sending and reading Messages with gun.js
Last active June 14, 2022 08:56
Send and receive messages with gun
/*so let's simplify you have
- your letters (all messages, yours & other peer) which you draw to DOM
- you have your outbox , when you say something, that the other person listens to with .on(...)
and adds to their letters when they arrive
- you listen with .on(...) the other peers messages and add them to letters when
they arrive
- on your send(){...} you would add the message to your letters
and to the outbox so your message can trigger the other persons .on */
class Chat {