Skip to content

Instantly share code, notes, and snippets.

View panlw's full-sized avatar
🎯
Focusing

Neo Pan panlw

🎯
Focusing
View GitHub Profile
@panlw
panlw / core.js
Created December 26, 2012 05:16
Simple JavaScript Inheritance
/**
* Simple JavaScript Inheritance
* @see http://ejohn.org/blog/simple-javascript-inheritance/
*
* By John Resig http://ejohn.org/
* MIT Licensed.
*/
var initializing = false,
fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
@panlw
panlw / Detect IE
Created December 26, 2012 05:42 — forked from DevReps/Detect IE
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@panlw
panlw / EnumUtil.cs
Last active December 21, 2015 22:09
List enum values
private static readonly string unknownEnumId = "unknown";
private static readonly Dictionary<Type, object> enumValuesCache =
new Dictionary<Type, object>();
/// <summary>
/// List all values anotated by XmlEnum
/// </summary>
/// <returns></returns>
public static List<XmlEnumValue<TEnum>> GetEnumValues<TEnum>() {
var t = typeof(TEnum);
@panlw
panlw / MyLanguageGen.sh
Last active March 22, 2016 06:29
Use Antlr v4 to do code generation for .NET
#!/bin/sh
# Generate Lexer/Visitor for syntax tree of MyLanguage
# You should download the jar file from
# http://tunnelvisionlabs.com/downloads/antlr/2013-02-27-antlr4-csharp-4.0.1-SNAPSHOT.7z
java -cp .:./antlr4-csharp-4.0.1-SNAPSHOT-complete.jar org.antlr.v4.CSharpTool -Dlanguage=CSharp_v3_5 -no-listener -visitor -package MyNamespace MyLanguage.g4
@panlw
panlw / MyLanguage.g4
Created August 29, 2013 02:06
Antlr v4 Sample - MyLanguage.g4
grammar MyLanguage;
// Rules
code : line+ ;
line : expr NEWLINE
| NEWLINE
;
expr : '(' expr ')' # group
@panlw
panlw / Start iTerm Here.workflow
Last active December 27, 2015 08:59
[Finder] Start iTerm Here
on run {input, parameters}
tell application "Finder"
set dirPath to "\"" & (POSIX path of (input as string)) & "\""
end tell
CdTo(dirPath)
end run
on CdTo(theDir)
tell application "iTerm"
activate
@panlw
panlw / Copy Path to Clipboard.workflow
Last active December 27, 2015 08:59
[Finder] Copy Path to Clipboard
on run {input, parameters}
tell application "Finder"
set sel to the selection as text
set the clipboard to POSIX path of sel
end tell
return input
end run
@panlw
panlw / gist:8050489
Created December 20, 2013 04:43
Pure CSS table using UL and LI
<html>
<head>
<title>pure css table</title>
<style>
.b_lt {border-left: 1px solid #000; border-top: 1px solid #000;}
.b_rb {border-right: 1px solid #000; border-bottom: 1px solid #000;}
.table{background:None;}
.table ul{float:left;margin:0px;padding:0px;}
.table ul li{list-style:none;padding:4px 9px;}
/*
* Property prefix hacks
*/
/* IE6 only - any combination of these characters */
_ - £ ¬ ¦
/* IE6/7 only - any combination of these characters */

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI