Skip to content

Instantly share code, notes, and snippets.

View btfak's full-sized avatar

btfak

View GitHub Profile
package main
import (
"fmt"
"log"
"os"
"runtime"
"runtime/debug"
"runtime/pprof"
"strconv"

Intro

The plan is to create a pair of executables (ngrok and ngrokd) that are connected with a self-signed SSL cert. Since the client and server executables are paired, you won't be able to use any other ngrok to connect to this ngrokd, and vice versa.

DNS

Add two DNS records: one for the base domain and one for the wildcard domain. For example, if your base domain is domain.com, you'll need a record for that and for *.domain.com.

Different Operating Systems

@btfak
btfak / doubangroupapi
Last active August 29, 2015 14:22 — forked from iamsk/doubangroupapi
import requests
from db import db
"""
The Douban Group API which not display on http://developers.douban.com/wiki/?title=api_v2
Base url: https://api.douban.com/v2
Group info: /group/:id
@btfak
btfak / doubangroupapi
Last active August 29, 2015 14:22 — forked from iamsk/doubangroupapi
import requests
from db import db
"""
The Douban Group API which not display on http://developers.douban.com/wiki/?title=api_v2
Base url: https://api.douban.com/v2
Group info: /group/:id
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
"github.com/garyburd/redigo/redis"
func urlencode(s string) (result string){
for _, c := range(s) {
if c <= 0x7f { // single byte
result += fmt.Sprintf("%%%X", c)
} else if c > 0x1fffff {// quaternary byte
result += fmt.Sprintf("%%%X%%%X%%%X%%%X",
0xf0 + ((c & 0x1c0000) >> 18),
0x80 + ((c & 0x3f000) >> 12),
0x80 + ((c & 0xfc0) >> 6),
0x80 + (c & 0x3f),
package main
import (
"fmt"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"time"
)
type Person struct {
git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
npm config delete proxy

Rate limiting with Redis

June 2011 - Chris O'Hara - (archived original post)

Rate limiting can be an effective way of conserving resources and preventing automated or nefarious activities on your site.

A common use case is to limit the amount of requests an IP can make over a certain time frame. For example, you might want to restrict users from using an expensive search utility on your site. If the user attempts to search more than 5 times a minute, you can redirect them to another page informing them that they need to wait.

IP based rate limiting is already in use on larger sites. Google and Yahoo both employ the technique to prevent (or at least complicate) automated requests to their services.

@btfak
btfak / useHexo.md
Created May 26, 2016 09:41
How to use Hexo and deploy to GitHub Pages