Skip to content

Instantly share code, notes, and snippets.

View nimezhu's full-sized avatar

Zhu Xiaopeng nimezhu

View GitHub Profile
@nimezhu
nimezhu / Caddyfile
Created December 21, 2021 18:58 — forked from ryanburnette/Caddyfile
Caddy v2.1 CORS whitelist
(cors) {
@origin{args.0} header Origin {args.0}
header @origin{args.0} Access-Control-Allow-Origin "{args.0}"
}
myawesomewebsite.com {
root * /srv/public/
file_server
header Access-Control-Allow-Methods "POST, GET, OPTIONS"
header Access-Control-Allow-Headers "*"
import cors https://member.myawesomewebsite.com
@nimezhu
nimezhu / iotest.go
Created October 23, 2016 03:35
Reading data from stdin or a file in Go
/*
If no filename given as argument, read from stdin. Allows use as piped tool.
mashbridge@hex iotest$ go build iotest.go
mashbridge@hex iotest$ ./iotest x.txt
file data: foo bar
mashbridge@hex iotest$ ./iotest < x.txt
stdin data: foo bar
@nimezhu
nimezhu / README
Created March 11, 2016 17:51 — forked from adilapapaya/README
Export Table Data to CSV using Javascript
Example code for exporting data in a table to a csv file.
package main
import (
"archive/tar"
"compress/gzip"
"flag"
"fmt"
"io"
"os"
)
@nimezhu
nimezhu / cgi.go
Last active August 29, 2015 14:23 — forked from larryli/cgi.go
// go build -ldflags "-s -w" -o index.cgi cgi.go
package main
import (
"fmt"
"net/http"
"net/http/cgi"
)
"""Kernel K-means"""
# Author: Mathieu Blondel <mathieu@mblondel.org>
# License: BSD 3 clause
import numpy as np
from sklearn.base import BaseEstimator, ClusterMixin
from sklearn.metrics.pairwise import pairwise_kernels
from sklearn.utils import check_random_state
import BaseHTTPServer
import cgi
from pprint import pformat
PORT = 6969
FILE_TO_SERVE = 'path/to/your/response/content.json'
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
"""
import SimpleHTTPServer
class CORSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def send_head(self):
"""Common code for GET and HEAD commands.
This sends the response code and MIME headers.
Return value is either a file object (which has to be copied
to the outputfile by the caller unless the command was HEAD,
and must be closed by the caller under all circumstances), or