Skip to content

Instantly share code, notes, and snippets.

View Nuhvi's full-sized avatar

Nuh Nuhvi

View GitHub Profile
@Nuhvi
Nuhvi / Scale factor needed to fit to contain
Last active April 22, 2020 11:06
A function I used to calculate the width and height of an object to fit in a parent element, during working on Single Stroke
export const scaleNeeded = (
src: { w: number; h: number },
trgt: { w: number; h: number },
): number => {
const wr = trgt.w / src.w;
const hr = trgt.h / src.h;
return Math.min(wr,hr);
};
java -Duser.timezone=UTC -jar logseq.jar
21-01-19 11:23:30 pop-os INFO [org.eclipse.jetty.util.log:169] - Logging initialized @5544ms to org.eclipse.jetty.util.log.Slf4jLog
Server is running on port 3000 !
21-01-19 11:23:30 pop-os INFO [com.zaxxer.hikari.HikariDataSource:80] - logseq-clj-db-pool - Starting...
Exception in thread "main" clojure.lang.ExceptionInfo: Error in component :hikari in system com.stuartsierra.component.SystemMap calling #'com.stuartsierra.component/start {:reason :com.stuartsierra.component/component-function-threw-exception, :function #'com.stuartsierra.component/start, :system-key :hikari, :component #app.components.hikari.Hikari{:db-spec {:database-name "logseq", :adapter "postgresql", :auto-commit true, :register-mbeans false, :password nil, :port-number 5432, :username nil, :max-lifetime 1800000, :minimum-idle 10, :connection-init-sql "set time zone 'UTC'", :connection-timeout 30000, :server-name "localhost", :read-only false, :maximum-pool-size 48, :idle-timeout 600000, :valida
@Nuhvi
Nuhvi / Duplicitous-hypercores.js
Last active January 9, 2022 16:41
Duplicitous hypercores
const Hypercore = require('hypercore');
const ram = require('random-access-memory');
const crypto = require('hypercore-crypto');
(async () => {
const keyPair = crypto.keyPair();
const a = new Hypercore(ram, { keyPair });
const b = new Hypercore(ram, a.key, { keyPair: keyPair });
await a.append(['a1', 'a2']);
// npm i hypercore@next hyperswarm@next random-access-memory
// Run `node resolve-hypercore.js <key you get from https://gist.github.com/Nazeh/60291b111f93928d8110ff0ae9ecea25>
const Hypercore = require('hypercore');
const Hyperswarm = require('hyperswarm');
const ram = require('random-access-memory');
const resolveCore = async (key) => {
const core = new Hypercore(ram, key, { valueEncoding: 'json' });
await core.ready();
// npm i [email protected] [email protected]
// Run `node create-hypercore.js` and pass the resulting key to https://gist.github.com/Nazeh/721368b93729dcfa00049c9de230f2ad
const Hypercore = require('hypercore');
const Hyperswarm = require('hyperswarm');
const createCore = async () => {
const core = new Hypercore('origin', { valueEncoding: 'json' });
await core.ready();
// Add blocks here if you want.
@Nuhvi
Nuhvi / gist:5a152d4ad20a8e240f9fee5accc50127
Last active June 24, 2022 07:19
Slashtags SDK quick communication setup
import { SDK } from '@synonymdev/slashtags-sdk';
const sdkA = await SDK.init({
persist: false, // No storage needed for this demo
primaryKey: Buffer.from('a'.repeat(64)), // Keep primary key consistent
});
console.log("Alice's DHT bootstrapped"); // Bootstrapping DHT takes some time.
const alice = sdkA.slashtag({ name: 'alice' });
alice.listen();
import Hypercore from 'hypercore';
import Hyperbee from 'hyperbee';
class Hyperstate extends Hypercore {
constructor(storage, key, opts) {
super(storage, key, opts);
this.state = {};
this.opening = this._open();
this.opening.catch(noop);
import Hyperswarm from 'hyperswarm'
import Corestore from 'corestore'
import ProtomuxRPC from 'protomux-rpc'
import RAM from 'random-access-memory'
import createTestnet from '@hyperswarm/testnet'
const testnet = await createTestnet()
const swarm_A = new Hyperswarm(testnet)
const store_A = new Corestore(RAM)
@Nuhvi
Nuhvi / successful_corestore_replicate_and_protomux_rpc.js
Created August 19, 2022 13:24
successful corestore.replicate + protomuxRPC
import Hyperswarm from 'hyperswarm'
import Corestore from 'corestore'
import ProtomuxRPC from 'protomux-rpc'
import Protomux from 'protomux'
import RAM from 'random-access-memory'
import createTestnet from '@hyperswarm/testnet'
import Hypercore from 'hypercore'
const testnet = await createTestnet()
@Nuhvi
Nuhvi / test.js
Last active October 9, 2022 14:55
test hyperdrive keychain PR backward compatibility
import * as SlashURL from '@synonymdev/slashtags-url'
import Corestore from 'corestore'
import Hyperdrive from 'hyperdrive'
import Hyperswarm from 'hyperswarm'
import RAM from 'random-access-memory'
const swarm = new Hyperswarm()
const corestore = new Corestore(RAM)
swarm.on('connection', socket => corestore.replicate(socket))