Skip to content

Instantly share code, notes, and snippets.

View iwasaki-kenta's full-sized avatar

Kenta Iwasaki iwasaki-kenta

  • Okayama, Japan
View GitHub Profile
package gossip_test
import (
"context"
"github.com/iwasaki-kenta/gossip"
"github.com/perlin-network/noise"
"github.com/perlin-network/noise/kademlia"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
"sync"
package gossip_test
import (
"context"
"github.com/iwasaki-kenta/gossip"
"github.com/perlin-network/noise"
"github.com/perlin-network/noise/kademlia"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
"sync"
package gossip_test
import (
"context"
"github.com/iwasaki-kenta/gossip"
"github.com/perlin-network/noise"
"github.com/perlin-network/noise/kademlia"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
"sync"
@iwasaki-kenta
iwasaki-kenta / channel.ts
Last active August 25, 2021 03:32
Go-like channels in TypeScript.
export class Deferred<T> {
promise: Promise<T>;
resolve: (value?: T | PromiseLike<T>) => void;
reject: (reason?: any) => void;
constructor() {
this.promise = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
@iwasaki-kenta
iwasaki-kenta / cuckoo.test.ts
Last active November 28, 2019 15:30
Cuckoo Filter. Assume content is pre-hashed with a 256-bit hash function.
import {Bucket, CuckooFilter} from "../src/cuckoo";
import {hash} from "../src/crypto";
import {assert} from "chai";
import {SmartBuffer} from "smart-buffer";
describe('CuckooFilter', () => {
it('sets and gets properly', () => {
const filter = new CuckooFilter(4, 100, 500);
for (let i = 0; i < 100; i++) {
/usr/bin/python3 /home/kenta/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/183.5912.18/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 44917 --file /home/kenta/Desktop/himitsu/main.py
pydev debugger: process 28305 is connecting
Connected to pydev debugger (build 183.5912.18)
Node 10 is proposing 5 transaction(s) to be finalized into Block 1.
Node 1 is proposing 5 transaction(s) to be finalized into Block 1.
Node 5 is proposing 3 transaction(s) to be finalized into Block 1.
Node 4 is proposing 2 transaction(s) to be finalized into Block 1.
Node 15 is proposing 2 transaction(s) to be finalized into Block 1.
Node 3 is proposing 5 transaction(s) to be finalized into Block 1.
[package]
name = "chat"
version = "0.1.0"
authors = ["Kenta Iwasaki <[email protected]>"]
edition = "2018"
[profile.release]
lto = true
[lib]
await client.pollConsensus({
onRoundEnded: msg => {
(async () => {
await contract.fetchAndPopulateMemoryPages();
console.log("Chat logs updated:", contract.test('get_messages', BigInt(0)));
})();
}
});
await contract.call(...[
{type: "uint32", value: 32}, // Pass in an unsigned little-endian 32-bit integer.
{type: "int64", value: JSBI.BigInt(-100000000)}, // Pass in a signed little-endian 64-bit integer.
{type: "string", value: "Another string"}, // Pass in a string.
{type: "raw", value: "hexadecimal_string_here_to_be_decoded_into_raw_bytes"}] // Pass in raw bytes hex-encoded.
)
await contract.call(
wallet,
'send_message',
JSBI.BigInt(0), // amount to send
JSBI.BigInt(250000), // gas limit
JSBI.BigInt(0), // gas deposit (not explained)
{type: "string", value: "Your chat message here!"},
);