Skip to content

Instantly share code, notes, and snippets.

View didasy's full-sized avatar
🤔
Really makes me think

Andida Syahendar didasy

🤔
Really makes me think
  • Indonesia
View GitHub Profile
@didasy
didasy / tokenPriceApi.js
Created November 2, 2021 03:43 — forked from Linch1/tokenPriceApi.js
Retrive the price of any bsc token from it's address without using external service like poocoin/dextools
let pancakeSwapAbi = [{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_WETH","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"},{"internalType":"uint256","name":"amountADesired","type":"uint256"},{"internalType":"uint256","name":"amountBDesired","type":"uint256"},{"internalType":"uint256","name":"amountAMin","type":"uint256"},{"internalType":"uint256","name":"amountBMin","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"addLiquidity","outputs":[{"internalType":"uint256","name":"amountA","type":"uint256"},{"internalType":"uint256","name":"amountB","type":"uint256"},{"interna
@didasy
didasy / remap.go
Last active December 2, 2020 09:06
Remap Range to Another Range
package main
import (
"fmt"
)
func main() {
unmappedValue := 512
minInput := 0
maxInput := 1023
@didasy
didasy / concurrent.go
Last active November 14, 2019 07:42
Example of Concurrent Processing With Channels
package main
import (
"context"
"flag"
"fmt"
"runtime"
ipgen "github.com/wahyuhadi/go-ipgen"
)
@didasy
didasy / app.js
Created March 29, 2019 12:15
Get Approximate LoC
let headers = new Headers();
//headers.append('Content-Type', 'text/json');
headers.append('Authorization', 'Basic ' + btoa('username' + ":" + 'token'))
fetch('https://api.github.com/repos/username/reponame/stats/contributors', { method:'GET', headers: headers })
.then(response => response.json())
.then(contributors => contributors
.map(contributor => contributor.weeks
.reduce((lineCount, week) => lineCount + week.a - week.d, 0)))
@didasy
didasy / tls-client.go
Created January 2, 2019 07:35 — forked from michaljemala/tls-client.go
SSL Client Authentication Golang sample
package main
import (
"crypto/tls"
"crypto/x509"
"flag"
"io/ioutil"
"log"
"net/http"
)
@didasy
didasy / .git-commit-template.txt
Created June 28, 2018 10:44 — forked from adeekshith/.git-commit-template.txt
This commit message template helps you write great commit messages and enforce it across teams.
# <type>: (If applied, this commit will...) <subject> (Max 50 char)
# |<---- Using a Maximum Of 50 Characters ---->|
# Explain why this change is being made
# |<---- Try To Limit Each Line to a Maximum Of 72 Characters ---->|
# Provide links or keys to any relevant tickets, articles or other resources
# Example: Github issue #23
@didasy
didasy / read_line.go
Created December 23, 2017 14:14
Read Line Helper Function for go-serial
func readByLine(port io.ReadWriteCloser) {
scanner := bufio.NewScanner(port)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
// Will return string
fmt.Println(scanner.Text())
}
}
@didasy
didasy / radixsort.go
Created December 4, 2017 08:01
Radix Sort Example for Go, taken from github.com/dgryski/go-radixsort
func Ints(E []int) {
// Algorithm from CLRS, chapter 8
const m = 256
n := len(E)
counts := make([]int, m)
src := E
@didasy
didasy / log.go
Created October 29, 2017 04:08 — forked from cespare/log.go
Golang apache logging
type ApacheLogRecord struct {
http.ResponseWriter
ip string
time time.Time
method, uri, protocol string
status int
responseBytes int64
elapsedTime time.Duration
}
@didasy
didasy / mhz19.ino
Last active January 22, 2019 09:03
Read MH-Z19 CO2 Sensor Data
// Make sure to wait the sensor to heat up first before attempting to get CO2 concentration data for the first time (approx 3 minutes preheat time).
int readCO2()
{
byte cmd[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
// command to ask for data
byte response[9]; // for answer
// co2Serial is a software serial instance
co2Serial.write(cmd, 9); //request PPM CO2