Skip to content

Instantly share code, notes, and snippets.

View bonfy's full-sized avatar
:octocat:
Nothing, but busy

Kai Chen bonfy

:octocat:
Nothing, but busy
View GitHub Profile
@bonfy
bonfy / graphql_example.py
Created August 23, 2019 23:18 — forked from gbaman/graphql_example.py
An example on using the Github GraphQL API with Python 3
# 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 07:00
Merge List Name Value like Json
package main
import (
"encoding/json"
"fmt"
)
type Param struct {
Name string `json:"name"`
Value interface{} `json:"value"`
@bonfy
bonfy / merge_json.go
Created May 7, 2019 08:22
Go merge json
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 December 7, 2018 03:08 — forked from dryaf/templates.go
labstack echo template inheritance recipe
package bla
import (
"io"
"html/template"
"path/filepath"
"strings"
)
// folder structure
@bonfy
bonfy / go-oauth-github.go
Last active November 28, 2018 07:52
Go oauth github
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"time"
package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)
@bonfy
bonfy / map2struct.go
Last active September 3, 2018 13:02
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 August 7, 2018 06:10 — forked from vsouza/.bashrc
Golang setup in Mac OSX with HomeBrew. Set `GOPATH` and `GOROOT` variables in zshell, fish or bash.
# 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 July 24, 2018 07:11 — forked from denji/golang-tls.md
Simple Golang HTTPS/TLS Examples

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 April 26, 2018 02:44
async example modify a global dict
# 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'])