Skip to content

Instantly share code, notes, and snippets.

View chiro-hiro's full-sized avatar
🤖
Bleep bloop, I am a robot. Eh, just kidding.

Chiro Hiro chiro-hiro

🤖
Bleep bloop, I am a robot. Eh, just kidding.
View GitHub Profile
@chiro-hiro
chiro-hiro / mary.bash
Last active November 22, 2023 15:46
SSH Tunneling + SOCKS
#!/usr/bin/env bash
# (C) 2023 Chiro & Mary
echo "Turning IPv6 off..."
networksetup -setv6off "Wi-Fi"
echo "Checking proxy configuration..."
networksetup -getsocksfirewallproxy "Wi-Fi"
echo "Setting proxy configuration..."
networksetup -setsocksfirewallproxy "Wi-Fi" 127.0.0.1 31337 off
echo "Turning proxy on..."
@chiro-hiro
chiro-hiro / ip2str.cpp
Last active August 20, 2023 16:41
Unsigned 32 bits IP address to string
/*
g++ -std=c++11 ip2str.cpp -o ip2str
ip2str 0xb01a8c0 0x100007f
*/
#include <sstream>
#include <iostream>
using namespace std;
/* Simplest version */
@chiro-hiro
chiro-hiro / merkle-tree.ts
Last active July 11, 2023 07:13
SnarkyJS Merkle tree example
/*
Description:
This example describes how developers can use Merkle Trees as a basic off-chain storage tool.
zkApps on Mina can only store a small amount of data on-chain, but many use cases require your application to at least reference big amounts of data.
Merkle Trees give developers the power of storing large amounts of data off-chain, but proving its integrity to the on-chain smart contract!
! Unfamiliar with Merkle Trees? No problem! Check out https://blog.ethereum.org/2015/11/15/merkling-in-ethereum/
@chiro-hiro
chiro-hiro / golang-slice.md
Last active June 18, 2023 05:18
first() and last() safe access in Golang

I'm pretty sure, Golang is a good language to learn and do development. I find out Golang doesn't support some popular safe slice access.

package main

import (
	"fmt"
	"reflect"
)

func main() {
@chiro-hiro
chiro-hiro / concat-uint8array.md
Last active May 19, 2023 16:36
Concat Uint8Array

Searching on the Internet to find a proper way to concat multiple arrays of Uint8Array but the result made me disapointed. "Why you guys so fucking lazy?", I asked.

So, I wrote mine so you can steal it genterly under the witness of MIT License. If you are end up here you are fucking lazy, you should do something about your life. Btw, don't just steal it leave me a damn star, Jesus!!.

TypeScript

function concatUint8Array(input: Uint8Array[], size?: number): Uint8Array {
  let concatedSize = 0;
  if (typeof size === 'undefined') {
@chiro-hiro
chiro-hiro / orandv1.md
Last active February 14, 2023 06:49
Get a private epoch from Orand V1

Orand JSON PRC was published at: https://orand-test-service.orochi.network/

Created new Orand's private epoch with CURL:

curl -X POST --data '{"method":"orand_newPrivateEpoch","params":["56", "0x68bE199e497FAe7ed11339BE388BF4a403CD1698"]}' https://orand-test-service.orochi.network/

Result for a single epoch:

@chiro-hiro
chiro-hiro / recover.ts
Last active December 25, 2022 12:39
Validate ethereum proof
import { ethers } from 'ethers';
(async () => {
let proofs = [
'0x4f54e1c15ca1d7aec6d16fcc8b524ef298a470b5dd61fd4aeccdd2abd4755e437340fe513a8267397ae468cc8643e1ea0d86f78d029ab35871c0d61d81ba32c51c',
'0x6fca48d5a3522f42984dda6ff662c63de7df537c40da53e74fcc77d00a73441c30c222612af565c74faed88830c4a4083fd9a98c46e5aeaae392dfe61c5a14941c',
'0xd3ba49eabe5cc487d012360e2d38c0238666f9ec596be5f3b7e542e67c448a187b09a9a5acda889366eb5789073b0a73961375f336d28beb4d78479405765e361b',
];
for (let i = 0; i < proofs.length; i += 1) {
console.log(
@chiro-hiro
chiro-hiro / fake-provider.ts
Created December 15, 2022 06:16
A wrapper of real JSON RPC provider
import { ethers } from 'ethers';
import { TillSuccess } from 'noqueue';
// Let's consider this is a dirty trick, to force the JSON RPC
// to retries several times before give up
function getFakeProvider(
provider: ethers.providers.StaticJsonRpcProvider,
): ethers.providers.StaticJsonRpcProvider {
const fakeProvider = {};
const injected: string[] = [];
@chiro-hiro
chiro-hiro / crossbeam.rs
Last active October 17, 2022 05:42
Example data sharing and channel
use crossbeam::scope;
use crossbeam_channel::{select, unbounded};
use env_logger::{Builder, Env};
use log::info;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::Duration;
fn main() {
Builder::from_env(Env::default().default_filter_or("info")).init();
@chiro-hiro
chiro-hiro / hardhat-unlock-signer.js
Last active October 12, 2022 13:13
Hardhat: Unlock any signer on mainnet forking
// MIT License
// Copyright (c) 2021 Dũng Trần a.k.a Chiro Hiro <chiro8x@gmail.com>
import { Signer } from '@ethersproject/abstract-signer'
import { Contract } from '@ethersproject/contracts'
import hre from 'hardhat'
interface IKeyValues {
[key: string]: string
}