Skip to content

Instantly share code, notes, and snippets.

View kenng's full-sized avatar
💭
calm

Ken Ng kenng

💭
calm
View GitHub Profile
@kenng
kenng / golang-prettyurl.go
Created March 25, 2017 03:05 — forked from techslides/golang-prettyurl.go
Generating Pretty Urls for SEO in GoLang using string and regex packages
type Post struct {
// db tag lets you specify the column name if it differs from the struct field
Id int64 `db:"post_id"`
Created int64
Title string `form:"Title" binding:"required"`
Body string `form:"Body"`
UserId int64 `form:"UserId"`
Url string
}
@kenng
kenng / channel_check.go
Created February 11, 2017 06:44 — forked from iamatypeofwalrus/channel_check.go
Check if a Go Channel is open or closed
// An intersting pattern for testing, but you can use the check anywhere
import "testing"
func TestCheckingChannel(t *testing.T) {
stop := make(chan bool)
// Testing some fucntion that SHOULD close the channel
func (stop chan bool) {
close(chan)
}(stop)
@kenng
kenng / xip_io_apache.md
Created December 19, 2016 02:40 — forked from trey/xip_io_apache.md
Use xip.io with a home-grown Apache VirtualHost setup

Use xip.io with a home-grown Apache VirtualHost setup

  • Start here.
  • Add a ServerAlias line to your VirtualHost definitions.
<VirtualHost *:80>
	DocumentRoot "/Users/you/Sites/sitename"
	ServerAlias sitename.*.xip.io
	ServerName sitename.dev
@kenng
kenng / docker-compose.yml
Last active November 14, 2016 10:34 — forked from anonymous/docker-compose.yml
docker-compose.yml created at Lorry.io
databaseadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: some-mysql
links:
- mysqlserver
ports:
- "8080:80"
mysqlserver:
image: mysql
@kenng
kenng / app.js
Created November 2, 2016 22:00 — forked from Turbo87/app.js
webpack + font-awesome test
require('font-awesome/css/font-awesome.css');
document.body.innerHTML = '<i class="fa fa-fw fa-question"></i>';
@kenng
kenng / golang-tls.md
Created October 27, 2016 07:26 — forked from denji/golang-tls.md
Simple Golang HTTPS/TLS Examples
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)
openssl ecparam -genkey -name secp384r1 -out server.key
<html lang="en-us"></html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" cntnt="IE=edge"/>
<title></title>
<meta name="viewport" cntnt="width=device-width, initial-scale=1, user-scalable=0, maximum-scale=1.0"/>
<meta name="description"/>
<link rel="stylesheet" href="css/.min.css"/>
<link rel="stylesheet" href="css/theme.min.css"/>
@kenng
kenng / detectcontenttype.go
Created September 6, 2016 06:02 — forked from rayrutjes/detectcontenttype.go
golang detect content type of a file
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()
// Only the first 512 bytes are used to sniff the content type.
buffer := make([]byte, 512)
_, err = file.Read(buffer)
if err != nil {
@kenng
kenng / README.md
Created August 15, 2016 05:56 — forked from magnetikonline/README.md
Setting Nginx FastCGI response buffer sizes.

Nginx FastCGI response buffer sizes

By default when Nginx starts receiving a response from a FastCGI backend (such as PHP-FPM) it will buffer the response in memory before delivering it to the client. Any response larger than the set buffer size is saved to a temporary file on disk. This process is outlined at the Nginx ngx_http_fastcgi_module page document page.

Introduction

Since disk is slow and memory is fast the aim is to get as many FastCGI responses passing through memory only. On the flip side we don't want to set an excessively large buffer as they are created and sized on a per request basis (i.e. it's not shared memory).

@kenng
kenng / ID.js
Last active August 8, 2016 06:53
ID - a unique ID/name generator for JavaScript
// Generate unique IDs for use as pseudo-private/protected names.
// Similar in concept to
// <http://wiki.ecmascript.org/doku.php?id=strawman:names>.
//
// The goals of this function are twofold:
//
// * Provide a way to generate a string guaranteed to be unique when compared
// to other strings generated by this function.
// * Make the string complex enough that it is highly unlikely to be
// accidentally duplicated by hand (this is key if you're using `ID`