Skip to content

Instantly share code, notes, and snippets.

View vinthewrench's full-sized avatar

Vinnie Moscaritolo vinthewrench

View GitHub Profile
@vinthewrench
vinthewrench / testshunt.c
Created February 9, 2022 22:58
Using gattlib to read values from victron smart shunt bluetooth
/*
clang++ -Wall -o testshunt testshunt.c /usr/lib/libgattlib.so
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "gattlib.h"
var localUser: ZDCLocalUser? = nil
ZDCManager.uiDatabaseConnection() .read { (transaction) in
localUser = transaction.object(forKey: localUserID!,
inCollection: kZDCCollection_Users) as? ZDCLocalUser
}
if let localUser = localUser {
if(!localUser.hasBackedUpAccessCode){
let setupVC = ZDCManager.uiTools().accountResumeSetup(forLocalUserID: localUserID)
{ ( localUserID:String?, completedActivation:Bool, shouldBackupAccessKey:Bool) in
// .. do something with new localUserID
}
// push the setupVC
@vinthewrench
vinthewrench / fetchingAvatar.swift
Created August 30, 2019 17:03
fetching an avatar
@IBOutlet public var userAvatar : UIImageView!
// assume user is ZDCLocalUser or ZDCUser object.
// fallback to default if no image found.
let defaultImage = {
return ZDCManager.imageManager().defaultUserAvatar()
}
// handle image found in cache
let preFetch = {(image: UIImage?, willFetch: Bool) in
@vinthewrench
vinthewrench / ZDCLocalUserread.swift
Created August 30, 2019 17:01
Accessing a ZDCLocalUser object
var localUser: ZDCLocalUser? = nil
ZDCManager.uiDatabaseConnection() .read { (transaction) in
localUser = transaction.object(forKey: localUserID!,
inCollection: kZDCCollection_Users) as? ZDCLocalUser
}
if let localUser = localUser {
print(user.displayName)
}
@vinthewrench
vinthewrench / createuser.swift
Created August 30, 2019 17:00
Creating or Signing-In to a User Account
let setupVC =
ZDCManager.uiTools().accountSetupViewController(withInitialViewController:nil,
canDismissWithoutNewAccount:true)
{ ( localUserID:String?, completedActivation:Bool, shouldBackupAccessKey:Bool) in
// .. do something with new localUserID
}
// push the setupVC
@vinthewrench
vinthewrench / outbox.json
Created August 27, 2019 18:14
outbox object
{
"data": "... encrypted outbox object here ...",
"keys": {
"UID:z55tqmfr9kix1p1gntotqpwkacpuoyno": {
"perms": "rws",
"key": "... wrapped key here ..."
},
"UID:jag15iacxneuco7owmegke63msbgyuyx": {
"perms": "r",
"key": "... wrapped key here ..."
@vinthewrench
vinthewrench / conversation.json
Created August 27, 2019 18:13
conversation object
{
"data": "... encrypted conversation object here ...",
"keys": {
"UID:z55tqmfr9kix1p1gntotqpwkacpuoyno": {
"perms": "rws",
"key": "... wrapped key here ..."
},
},
"dirPrefix": "F8622C33B26C43C7B7DB3A6B26C60057",
"version": 3
// Setting a tag
cloudTransaction.setTag(fileURL, forNodeID: node.uuid, withIdentifier: "url")
// Getting a tag
let fileURL = cloudTransaction.tag(forNodeID: node.uuid, withIdentifier: "url")
let comps: ZDCNodeMetaComponents = [.metadata]
zdc.downloadManager!.downloadNodeMeta( node,
components: comps,
options: options,
completionQueue: DispatchQueue.global())
{(cloudDataInfo: ZDCCloudDataInfo?, metadata: Data?, thumbnail: Data?, error: Error?) in
// data downloaded & decrypted for you
}