Skip to content

Instantly share code, notes, and snippets.

@nnkken
nnkken / in-order.js
Created May 5, 2023 12:57
Inorder traversal of binary tree, from recursive to iterative
const tree = {
value: 'A',
left: {
value: 'B',
left: {
value: 'D',
left: {
value: 'H',
},
right: {
@nnkken
nnkken / main.js
Last active July 21, 2022 12:34
Count online voting power during upgrade
const axios = require('axios');
const BigNumber = require('bignumber.js');
const lcdEndpoint = 'http://localhost:1317';
const rpcEndpoint = 'http://localhost:26657';
const nilVote = 'nil-Vote';
const lcd = axios.create({
baseURL: lcdEndpoint,
@nnkken
nnkken / genesis.json
Created July 28, 2021 13:09
genesis.json for like `likecoin-public-testnet-3`
{
"app_hash": "",
"app_state": {
"auth": {
"accounts": [
{
"@type": "/cosmos.auth.v1beta1.BaseAccount",
"account_number": "0",
"address": "cosmos14r0a7xtf3cmp7rtyf4jkjhsypf69u5jvcc9cjx",
"pub_key": null,
@nnkken
nnkken / genesis.json
Created July 8, 2021 18:31
Genesis file for likecoin-chain-public-testnet-2
{
"genesis_time": "2021-07-09T00:00:00Z",
"chain_id": "likecoin-chain-public-testnet-2",
"consensus_params": {
"block": {
"max_bytes": "22020096",
"max_gas": "-1",
"time_iota_ms": "1000"
},
"evidence": {
@nnkken
nnkken / genesis.json
Last active May 26, 2021 04:16
Genesis file for likecoin-chain-testnet-internal-sheungwan
{
"genesis_time": "2021-05-26T03:30:00Z",
"chain_id": "likecoin-testnet-sanpokong-1",
"consensus_params": {
"block": {
"max_bytes": "22020096",
"max_gas": "-1",
"time_iota_ms": "1000"
},
"evidence": {
@nnkken
nnkken / 200000-addresses.js
Created June 23, 2020 10:13
create 200000 Cosmos addresses test
const crypto = require('crypto');
const secp256k1 = require('secp256k1');
const bech32 = require('bech32');
const createHash = require('create-hash');
function createSigner(privateKey) {
const publicKeyArr = secp256k1.publicKeyCreate(privateKey, true);
const publicKey = Buffer.from(publicKeyArr);
const sha256 = createHash('sha256');
const ripemd = createHash('ripemd160');
{
"genesis_time": "2019-11-25T08:30:32.551547Z",
"chain_id": "local-test-chain",
"consensus_params": {
"block": {
"max_bytes": "22020096",
"max_gas": "-1",
"time_iota_ms": "1000"
},
"evidence": {
@nnkken
nnkken / keybase.md
Created November 13, 2019 09:00
keybase.md

Keybase proof

I hereby claim:

  • I am nnkken on github.
  • I am nnkken (https://keybase.io/nnkken) on keybase.
  • I have a public key ASA7JfqneYUkGEU9I9zgQOdkHTVWDuGTX6dh3koqYD0vwwo

To claim this, I am signing this object:

@nnkken
nnkken / sign.js
Created November 7, 2019 03:55
Cosmos SDK transaction signing and verifying
const secp256k1 = require('secp256k1');
const bech32 = require('bech32');
const createHash = require('create-hash');
const jsonStringify = require('fast-json-stable-stringify');
function createSigner(privateKey) {
console.log(`private key: ${privateKey.toString('hex')}`);
const publicKey = secp256k1.publicKeyCreate(privateKey, true);
console.log(`public key: ${publicKey.toString('base64')}`);
const sha256 = createHash('sha256');
@nnkken
nnkken / setjump.c
Created September 14, 2019 11:54
Setjump test
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
jmp_buf env;
int my_func(int a, int b) {
if (b == 0) {
printf("do not allow division by 0\n");
longjmp(env, 1);