Skip to content

Instantly share code, notes, and snippets.

View jetsanix's full-sized avatar
💭
💭💭💭

jet tsang zeon-git jetsanix

💭
💭💭💭
View GitHub Profile
@trunet
trunet / graphql-go-mongodb-example.go
Created June 18, 2018 13:28 — forked from aquiseb/graphql-go-mongodb-example.go
Minimal example of GraphQL Golang and MongoDB playing nicely together. Edit
// Embedded in this article https://medium.com/p/c98e491015b6
package main
import (
"context"
"fmt"
"log"
"net/http"
"time"
@Rich-Harris
Rich-Harris / footgun.md
Last active April 19, 2024 07:47
Top-level `await` is a footgun

Edit — February 2019

This gist had a far larger impact than I imagined it would, and apparently people are still finding it, so a quick update:

  • TC39 is currently moving forward with a slightly different version of TLA, referred to as 'variant B', in which a module with TLA doesn't block sibling execution. This vastly reduces the danger of parallelizable work happening in serial and thereby delaying startup, which was the concern that motivated me to write this gist
  • In the wild, we're seeing (async main(){...}()) as a substitute for TLA. This completely eliminates the blocking problem (yay!) but it's less powerful, and harder to statically analyse (boo). In other words the lack of TLA is causing real problems
  • Therefore, a version of TLA that solves the original issue is a valuable addition to the language, and I'm in full support of the current proposal, which you can read here.

I'll leave the rest of this document unedited, for archaeological

@mishak87
mishak87 / go-lang-vanity-imports.conf
Created April 12, 2015 20:26
nginx vanity imports for go(lang)
location ~ /(?<namespace>[a-z][a-z0-9]*)/(?<package>[a-z][a-z0-9]*) {
if ($args = "go-get=1") {
add_header Content-Type text/html;
return 200 '<meta name="go-import" content="$host/$namespace/$package git https://git.$host/$namespace/$package">';
}
}
@ifels
ifels / vim_NERDTree
Last active April 8, 2023 19:12
vim NERDTree 快捷键
ctrl + w + h 光标 focus 左侧树形目录
ctrl + w + l 光标 focus 右侧文件显示窗口
ctrl + w + w 光标自动在左右侧窗口切换
ctrl + w + r 移动当前窗口的布局位置
o 在已有窗口中打开文件、目录或书签,并跳到该窗口
go 在已有窗口 中打开文件、目录或书签,但不跳到该窗口
t 在新 Tab 中打开选中文件/书签,并跳到新 Tab
T 在新 Tab 中打开选中文件/书签,但不跳到新 Tab
i split 一个新窗口打开选中文件,并跳到该窗口
gi split 一个新窗口打开选中文件,但不跳到该窗口
@klzgrad
klzgrad / Naive-VPN.md
Created November 17, 2014 00:43
朴素VPN:一个纯内核级静态隧道

朴素VPN:一个纯内核级静态隧道

由于路由管控系统的建立,实时动态黑洞路由已成为最有效的封锁手段,TCP连接重置和DNS污染成为次要手段,利用漏洞的穿墙方法已不再具有普遍意义。对此应对方法是多样化协议的VPN来抵抗识别。这里介绍一种太简单、有时很朴素的“穷人VPN”。

朴素VPN只需要一次内核配置(Linux内核),即可永久稳定运行,不需要任何用户态守护进程。所有流量转换和加密全部由内核完成,原生性能,开销几乎没有。静态配置,避免动态握手和参数协商产生指纹特征导致被识别。并且支持NAT,移动的内网用户可以使用此方法。支持广泛,基于L2TPv3标准,Linux内核3.2+都有支持,其他操作系统原则上也能支持。但有两个局限:需要root权限;一个隧道只支持一个用户。

朴素VPN利用UDP封装的静态L2TP隧道实现VPN,内核XFRM实现静态IPsec。实际上IP-in-IP隧道即可实现VPN,但是这种协议无法穿越NAT,因此必须利用UDP封装。内核3.18将支持Foo-over-UDP,在UDP里面直接封装IP,与静态的L2TP-over-UDP很类似。

创建一个朴素VPN

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
@lhaagsma
lhaagsma / PoodleIptables
Created October 16, 2014 20:27
Drop successful SSLv3 connections using IPtables
# Matching 'SSL SERVER HELLO' packets using IPtables
# Using some connection tracking to make sure not
# to match randomly in the middle of some huge SSL
# session.
iptables --insert INPUT -p tcp --sport 443 \
-m connbytes --connbytes-mode bytes --connbytes-dir both --connbytes 0:500 \
-m state --state ESTABLISHED \
-m length --length 46:375 \
-m u32 --u32 "\
# Basic Strongswan ikev2 server setup
* paltform: atlantic.net ubuntu 14.04 x64
* the commands below are run with root account
## Strongswan
```
apt-get install strongswan
apt-get install iptables iptables-persistent
```
@agrlh
agrlh / install_netatalk_debian.md
Last active March 27, 2024 08:52
Compiling and installing netatalk 3.1.2 on Debian (used for my RaspberryPi TimeCapsule)

Building and setting up netatalk 3.1.2 on Debian

1. Build

Install dependencies

sudo apt-get install automake libtool build-essential pkg-config checkinstall git-core avahi-daemon libavahi-client-dev libssl-dev libdb5.1-dev db-util db5.1-util libgcrypt11 libgcrypt11-dev libcrack2-dev libpam0g-dev libdbus-1-dev libdbus-glib-1-dev libglib2.0-dev libwrap0-dev systemtap-sdt-dev libacl1-dev libldap2-dev

Download and unpack netatalk 3.1.2

测试平台:DigitalOcean VPS ubuntu14.04 x64, strongswan5.2.2

运行以下命令请使用root权限

一:安装strongswan

由于ubuntu软件仓库中strongswan版本较低,因此从官网源码编译安装

apt-get install build-essential     #编译环境
aptitude install libgmp10 libgmp3-dev libssl-dev pkg-config libpcsclite-dev libpam0g-dev     #编译所需要的软件