Skip to content

Instantly share code, notes, and snippets.

View smallnest's full-sized avatar

smallnest smallnest

View GitHub Profile
@smallnest
smallnest / cgo.md
Created August 28, 2018 11:55 — forked from zchee/cgo.md
cgo convert list

See also, http://libraryofalexandria.io/cgo/

Using Go cgo

cgo has a lot of trap.
but Not "C" pkg also directory in $GOROOT/src. IDE's(vim) Goto command not works.

So, Here collect materials.

package main
import (
"crypto/tls"
"fmt"
"net/http"
"golang.org/x/crypto/acme/autocert"
)
1. GOCACHE=off , go 1.11这个环境变量会被去除
2. -count=1
3. go clean -cache
4. -a 重编译
5. -gcflags="all=-a" 重编译
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
@smallnest
smallnest / main.go
Created August 9, 2018 10:49 — forked from wolfeidau/main.go
Epoll example in golang starting point
package main
//
// Starting point is from http://gcmurphy.wordpress.com/2012/11/30/using-epoll-in-go/
//
import (
"fmt"
"os"
"syscall"
@smallnest
smallnest / epoll.go
Created August 9, 2018 10:47 — forked from artyom/epoll.go
Using epoll from Go.
package main
import (
"log"
"os"
"syscall"
)
func main() {
f, err := os.Open("/tmp/pipe")
@smallnest
smallnest / quick_sort.go
Last active June 26, 2018 11:05
golang quick_sort by goroutines
package main
import (
"fmt"
"math/rand"
"sort"
"time"
"github.com/psilva261/timsort"
)
@smallnest
smallnest / gbkbig5.go
Created June 26, 2018 09:19 — forked from zhang0098/gbkbig5.go
Golang GBK Big5 from/to UTF-8 转换
import (
"bytes"
"io/ioutil"
"golang.org/x/text/encoding/traditionalchinese"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
)
//convert GBK to UTF-8
func Decodegbk(s []byte) ([]byte, error) {
I := bytes.NewReader(s)
@smallnest
smallnest / gbkbig5.go
Created June 26, 2018 09:19 — forked from 18o/gbkbig5.go
Golang GBK Big5 from/to UTF-8 转换
import (
"bytes"
"io/ioutil"
"golang.org/x/text/encoding/traditionalchinese"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
)
//convert GBK to UTF-8
func Decodegbk(s []byte) ([]byte, error) {
I := bytes.NewReader(s)
@smallnest
smallnest / gist:5a3d490562084983abc0ba7dc627744d
Created June 26, 2018 09:17 — forked from wendal/gist:4537679
演示golang转编码 (gb2312 --> utf8)
package main
import (
iconv "github.com/djimenez/iconv-go"
"io/ioutil"
"log"
"net/http"