Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Ha ĐANG hadv

🎯
Focusing
View GitHub Profile
@hadv
hadv / nginx.conf
Created Oct 17, 2019 — forked from micho/nginx.conf
nginx config for http/https proxy to localhost:3000
View nginx.conf
First, install nginx for mac with "brew install nginx".
Then follow homebrew's instructions to know where the config file is.
1. To use https you will need a self-signed certificate: https://devcenter.heroku.com/articles/ssl-certificate-self
2. Copy it somewhere (use full path in the example below for server.* files)
3. sudo nginx -s reload
4. Access https://localhost/
Edit /usr/local/etc/nginx/nginx.conf:
View keybase.md

Keybase proof

I hereby claim:

  • I am hadv on github.
  • I am dvietha (https://keybase.io/dvietha) on keybase.
  • I have a public key ASAm1r0IYGKtBL7GQIkzqcAxxskaUhX4l4VH-wP7wFuGego

To claim this, I am signing this object:

@hadv
hadv / sendSignedTransaction.js
Last active Jul 22, 2019
sendSignedTransaction
View sendSignedTransaction.js
web3.eth.sendSignedTransaction(raw)
.on('transactionHash', (hash) => {
console.log('sent tx with hash: ' + hash);
})
.on('error', (err) => {
console.log('error: ' + err);
});
View installing-get-on-centos.md
$ sudo yum -y update
$ sudo yum -y install golang
$ sudo yum -y install gmp-devel
$ sudo yum -y install git
$ git clone https://github.com/ethereum/go-ethereum
$ cd go-ethereum/
$ make geth
$ ls -al build/bin/geth
@hadv
hadv / main.go
Created Apr 25, 2019 — forked from wayneashleyberry/main.go
Go http server with graceful shutdown
View main.go
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
)
View keybase.md

Keybase proof

I hereby claim:

  • I am hadv on github.
  • I am dvietha (https://keybase.io/dvietha) on keybase.
  • I have a public key ASApRXY1Pj2ToSDec4ZOPXIcHWyp8qlQ8GE_obqoMU1OjAo

To claim this, I am signing this object:

View main.go
func main() {
mw := multiWeatherProvider{
openWeatherMap{apiKey: "5bd6d7d469feee97788f51744f8c2910"},
apixu{apiKey: "ff8b321075a54e7288794851162712"},
}
http.HandleFunc("/weather/", func(w http.ResponseWriter, r *http.Request) {
begin := time.Now()
city := strings.SplitN(r.URL.Path, "/", 3)[2]
View multiWeatherProvider.go
func (w multiWeatherProvider) temperature(city string) (float64, error) {
// Make a channel for temperatures, and a channel for errors.
// Each provider will push a value into only one.
temps := make(chan float64, len(w))
errs := make(chan error, len(w))
// For each provider, spawn a goroutine with an anonymous function.
// That function will invoke the temperature method, and forward the response.
for _, provider := range w {
go func(p weatherProvider) {
View apixu.go
type apixu struct {
apiKey string
}
func (w apixu) temperature(city string) (float64, error) {
resp, err := http.Get("http://api.apixu.com/v1/current.json?key=" + w.apiKey + "&q=" + city)
if err != nil {
return 0, err
}
View openWeatherMap.go
type openWeatherMap struct {
apiKey string
}
func (w openWeatherMap) temperature(city string) (float64, error) {
resp, err := http.Get("http://api.openweathermap.org/data/2.5/weather?APPID=" + w.apiKey + "&q=" + city)
if err != nil {
return 0, err
}
You can’t perform that action at this time.