Skip to content

Instantly share code, notes, and snippets.

View phoorichet's full-sized avatar

Lock Phoorichet phoorichet

View GitHub Profile
@phoorichet
phoorichet / rand.sh
Created September 1, 2020 03:53
Generate Random Bytes
#!/bin/bash
openssl rand -base64 <desired length>

Weekly Order API

This document is assumed that you're already familiar with Graphql.

NOTE: This API is under heavy development. Please link to development GraphiQL Endpoint for full and upated schema details.

1. Signup

Type: Mutation

@phoorichet
phoorichet / list_validator_unbounded_amount.js
Last active August 16, 2019 04:15
List the total rewards amount delegator withdrawn from validators
const axios = require("axios")
const BN = require("bignumber.js")
let page = 1
// map[validator] => amount
const validators = new Map()
// add to url query `validator=${wantValidator}`
const wantValidator = 'default:0xa5b2C08c1DcD58d819317b79CbC9b5A8566bDF73'
Offset: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000: 7F 45 4C 46 02 01 01 00 00 00 00 00 00 00 00 00 .ELF............
00000010: 03 00 3E 00 01 00 00 00 30 05 00 00 00 00 00 00 ..>.....0.......
00000020: 40 00 00 00 00 00 00 00 30 19 00 00 00 00 00 00 @.......0.......
00000030: 00 00 00 00 40 00 38 00 09 00 40 00 1D 00 1C 00 ....@.8...@.....
00000040: 06 00 00 00 04 00 00 00 40 00 00 00 00 00 00 00 ........@.......
00000050: 40 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 @.......@.......
00000060: F8 01 00 00 00 00 00 00 F8 01 00 00 00 00 00 00 x.......x.......
00000070: 08 00 00 00 00 00 00 00 03 00 00 00 04 00 00 00 ................
00000080: 38 02 00 00 00 00 00 00 38 02 00 00 00 00 00 00 8.......8.......
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func producer(total int) chan *http.Request {
queue := make(chan *http.Request)
package main
import (
"fmt"
"log"
"net/http"
"time"
)
func main() {
package main
import (
"fmt"
"io/ioutil"
"net/http"
"sync"
)
func producer(total int) chan *http.Request {
// ...
func main() {
// create fixed size queue
queue := producer(1000)
// create consumers to consume work in the queue
consumerCount := 10
for i := 0; i < consumerCount; i++ {
go consumer(queue, i)
}
func consumer(queue chan *http.Request, id int) {
// create http client
client := &http.Client{}
// consumer runs forever until the queue is closed
for {
select {
case req, ok := <-queue:
if !ok {
// not ok means queue is closed
func producer(total int) chan *http.Request {
queue := make(chan *http.Request)
// make sure that this the for-loop is run using goroutine
// otherwiser, it will block
go func() {
for i := 0; i < total; i++ {
// ignore error assuming that the request valid
req, _ := http.NewRequest("GET", "http://localhost:9000", nil)
queue <- req
}