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 / 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
package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)
@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 / bobp-python.md
Created February 1, 2018 13:09 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@bonfy
bonfy / example.go
Created December 6, 2017 01:35 — forked from linxlad/example.go
simple DRY controller. golang github.com/labstack/echo example
package main
import (
"fmt"
"net/http"
"reflect"
"strconv"
"github.com/jinzhu/gorm"
"github.com/labstack/echo"
@bonfy
bonfy / processify.py
Created September 13, 2017 01:41 — forked from schlamar/processify.py
processify
import os
import sys
import traceback
from functools import wraps
from multiprocessing import Process, Queue
def processify(func):
'''Decorator to run a function as a process.
Be sure that every argument and the return value
@bonfy
bonfy / uninstall_homebrew.sh
Created January 6, 2017 12:58 — forked from mxcl/uninstall_homebrew.sh
Uninstall Homebrew
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e
@bonfy
bonfy / beautiful_idiomatic_python.md
Created December 7, 2016 14:06 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]: