Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Nothing, but busy

Kai Chen bonfy

:octocat:
Nothing, but busy
View GitHub Profile
@bonfy
bonfy / graphql_example.py
Created Aug 23, 2019 — forked from gbaman/graphql_example.py
An example on using the Github GraphQL API with Python 3
View graphql_example.py
# An example to get the remaining rate limit using the Github GraphQL API.
import requests
headers = {"Authorization": "Bearer YOUR API KEY"}
def run_query(query): # A simple function to use requests.post to make the API call. Note the json= section.
request = requests.post('https://api.github.com/graphql', json={'query': query}, headers=headers)
if request.status_code == 200:
@bonfy
bonfy / merge_list_name_value.go
Created May 17, 2019
Merge List Name Value like Json
View merge_list_name_value.go
package main
import (
"encoding/json"
"fmt"
)
type Param struct {
Name string `json:"name"`
Value interface{} `json:"value"`
View merge_json.go
package main
import (
"encoding/json"
"fmt"
)
func main() {
inputJSON := `{"environment": "production", "runbook":"http://url","message":"there is a problem"}`
out := map[string]interface{}{}
@bonfy
bonfy / templates.go
Created Dec 7, 2018 — forked from dryaf/templates.go
labstack echo template inheritance recipe
View templates.go
package bla
import (
"io"
"html/template"
"path/filepath"
"strings"
)
// folder structure
@bonfy
bonfy / go-oauth-github.go
Last active Nov 28, 2018
Go oauth github
View go-oauth-github.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"time"
View gist:c25d507fb416ee5c76d4b30424f1ba53
package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)
@bonfy
bonfy / map2struct.go
Last active Sep 3, 2018
map2struct.go
View map2struct.go
package main
import (
"errors"
"fmt"
"reflect"
)
func SetField(obj interface{}, name string, value interface{}) error {
structValue := reflect.ValueOf(obj).Elem()
@bonfy
bonfy / .bashrc
Created Aug 7, 2018 — forked from vsouza/.bashrc
Golang setup in Mac OSX with HomeBrew. Set `GOPATH` and `GOROOT` variables in zshell, fish or bash.
View .bashrc
# Set variables in .bashrc file
# don't forget to change your path correctly!
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
@bonfy
bonfy / golang-tls.md
Created Jul 24, 2018 — forked from denji/golang-tls.md
Simple Golang HTTPS/TLS Examples
View golang-tls.md

Moved to git repository: https://github.com/denji/golang-tls

Generate private key (.key)
# Key considerations for algorithm "RSA" ≥ 2048-bit
openssl genrsa -out server.key 2048

# Key considerations for algorithm "ECDSA" ≥ secp384r1
# List ECDSA the supported curves (openssl ecparam -list_curves)
@bonfy
bonfy / async_example.py
Created Apr 26, 2018
async example modify a global dict
View async_example.py
# coding: utf-8
import asyncio
g = {'num': 1}
async def add(g, num=1):
print(f'origin {num} from', g['num'])
await asyncio.sleep(10)
print(f'do add {num} from', g['num'])