Skip to content

Instantly share code, notes, and snippets.

@raecoo
raecoo / redis-pools.go
Last active November 29, 2017 09:12
build the multiple Redis pool into an array
package main
import (
"fmt"
"github.com/garyburd/redigo/redis"
"strings"
"time"
)
const (
@raecoo
raecoo / DSS-1.js
Last active November 22, 2017 00:46
TOD indicators
declare lower;
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 10;
input priceH = high;
input priceL = low;
input priceC = close;
input averageType = AverageType.EXPONENTIAL;
@raecoo
raecoo / Accumulation swing index.js
Last active November 21, 2017 05:12
DSS Bressert indicator for Tradingview
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 26/05/2014
// The Accumulation Swing Index is a cumulative total of the Swing Index.
// The Accumulation Swing Index was developed by Welles Wilder.
// The SwingIndex function was developed to help cut through the maze of
// Open, High, Low and Close prices to indicate the real strength and direction
// of the market. The Swing Index function looks at the Open, High, Low and
// Close values for a two-bar period. The theory is that there are four cross-bar
// and one intra-bar comparisons that are strong indicators of an up or down day.
// The Swing Index returns a number between -100 and 100. If the factors point toward
@raecoo
raecoo / ip-address.go
Created November 16, 2017 06:27
IP Address format convert
func Ip2long(ipAddr string) (uint32, error) {
ip := net.ParseIP(ipAddr)
if ip == nil {
return 0, errors.New("Wrong IpAddr format")
}
ip = ip.To4()
return binary.BigEndian.Uint32(ip), nil
}
func Long2ip(ipLong uint32) string {
@raecoo
raecoo / benchmark+go+nginx.md
Created November 6, 2017 08:24
Benchmarking Nginx with Go

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
@raecoo
raecoo / gist:149928dace56b1abfa30be45c548b757
Created November 2, 2017 07:59 — forked from maximebf/gist:3986659
Jinja2 macro to render WTForms fields with Twitter Bootstrap
{% macro form_field(field) -%}
{% set with_label = kwargs.pop('with_label', False) %}
{% set placeholder = '' %}
{% if not with_label %}
{% set placeholder = field.label.text %}
{% endif %}
<div class="control-group {% if field.errors %}error{% endif %}">
{% if with_label %}
<label for="{{ field.id }}" class="control-label">
{{ field.label.text }}{% if field.flags.required %} *{% endif %}:
@raecoo
raecoo / dumper.py
Last active November 1, 2017 22:26
logger
from multiprocessing import Pool
import os, time
import logging
import logging.handlers
import threading
class TopicDumper(threading.Thread):
@raecoo
raecoo / gist:bf261f88acfff7d6d7ef8990485eeef4
Created October 26, 2017 08:46 — forked from aodin/gist:9493190
Parsing JSON in a request body with Go
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
)
type Message struct {
@raecoo
raecoo / json.go
Last active October 25, 2017 08:10
String convert to json or map in Go
import (
"encoding/json"
"fmt"
"os/exec"
"strings"
)
var cfg = "[{'status': 'success', 'type': 'masterInfo', 'result': '[{read: 2.0, write: 1.2}, {read_mb: 4.0, write: 3.2}]'}]"
func main() {
@raecoo
raecoo / redis.conf
Last active October 26, 2017 05:02
Ubuntu + Redis setup
# change following options only
supervised systemd
dir /var/lib/redis
logfile "/var/lig/redis/redis.log"
# slaveof <masterip> <masterport>