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 / gun.helper.js
Last active July 15, 2023 10:48
Gun user-space and public graph get/set with signing and encryption
/**
* get and put encrypted and/or signed material to paths in Gun
* FIXME: Investigate why root level put doesn't work
*
* DONE: Add signing to make objects unwritable by others
* Changes:
* - 25.02.2020
* - added mergedeep to better merge deeper objects between themselves
* - added pair.osign option to only sign not encrypt when passing existing pairs
**/
@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 {
@jabis
jabis / mapredmoo.js
Last active September 2, 2016 12:18
MooTools Promise.Series map/reduce
(function(){
this.Promise = new Class({
Implements: Class.Thenable,
initialize: function(promise) {
if (typeof promise !== 'function')
throw new TypeError('Promise accepts only a function constructor!');
try {
promise(this.resolve.bind(this), this.reject.bind(this));
} catch (e) {
this.reject(e);
@jabis
jabis / validator
Created April 13, 2016 18:51
validator.js
var validator = module.exports = {
isDecimal : function(input) { return (/^(?=.)\d*(\.\d{1,9})?$/.test(input)); },
isNull : function(input) { return ((input == null) || (typeof input === "string" && input.replace(/\s/g, "") == "") || (typeof input === "undefined") || (input.length == 0)); },
isAlpha : function(input) { return (/^[a-zA-Z]+$/.test(input) && !validator.isNull(input)); },
isAlphanumeric : function(input) { return !(/\WöäåÖÄÅ/.test(input)); },
isNumeric : function(input) { return (/^-?(?:0$0(?=\d*\.)|[1-9]|0)\d*(\.\d+)?$/.test(input)); },
isEmail : function(input) { return (!validator.isNull() || (/^(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]\.?){0,63}[a-z0-9!#$%&'*+\/=?^_`{|}~-]@(?:(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\])$/i).test(input)); }
};
@jabis
jabis / renew.sh
Last active December 3, 2015 23:22
Letsencrypt auto-renewal crontab script by majuscule
#!/usr/bin/env bash
# Auto renewal script for letsencrypt
# https://disinclined.org/share/renew-ssl-certificates.sh.txt
# this script is for singular domain-named files in /etc/nginx/sites-enabled, so check paths to match and enjoy
# Created by majuscule @ #letsencrypt on freenode ( dylan@disinclined.org )
ERROR=0
for DOMAIN in $(ls -1 /etc/nginx/sites-enabled); do
/root/letsencrypt/letsencrypt-auto certonly \
--server 'https://acme-v01.api.letsencrypt.org/directory' \
/*
---
script: Date.Finnish.js
name: Date.Finnish
description: Date messages for Finnish language.
license: MIT-style license