This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
//一致性哈希(Consistent Hashing) | |
//author: Xiong Chuan Liang | |
//date: 2015-2-20 | |
import ( | |
"fmt" | |
"hash/crc32" | |
"sort" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
// Suggestions from golang-nuts | |
// http://play.golang.org/p/Ctg3_AQisl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var str = "vfs.fs.size[C:,pfree]" | |
var matched = str.match(/^vfs.fs.size\[(.*?):,pfree\]$/) | |
//matched[1]="C" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"flag" | |
"fmt" | |
"github.com/hashicorp/consul/api" | |
"log" | |
"math/rand" | |
"net/http" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
session_id=$(curl -s -XPUT "${consul_address}/v1/session/create" -d "{\"Name\": \"${task_name}\"}" | jq -r '.ID') | |
acquire_lock() { | |
session_id=${1} | |
echo "Trying to acquire the lock..." | |
result=$(curl -s -XPUT "${consul_address}/v1/kv/locks/${task_name}/.lock?acquire=${session_id}") | |
[ "${result}" == "true" ] && echo "Lock acquired" | |
} | |
release_lock() { | |
session_id=${1} | |
echo "Releasing the lock..." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Fetcher interface { | |
// Fetch returns the body of URL and | |
// a slice of URLs found on that page. | |
Fetch(url string) (body string, urls []string, err error) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Two dashes start a one-line comment. | |
--[[ | |
Adding two ['s and ]'s makes it a | |
multi-line comment. | |
--]] | |
---------------------------------------------------- | |
-- 1. Variables and flow control. | |
---------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Package main serves as an example application that makes use of the observer pattern. | |
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
type ( | |
// Event defines an indication of a point-in-time occurrence. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main(){ | |
var n int = 10 | |
var chs = make([]chan int, n) | |
var worker = func(n int, c chan int){ | |
for i:=0;i<n;i++{ | |
c<-i | |
} | |
close(c) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create the datadog user with select only permissions: | |
# CREATE USER datadog WITH PASSWORD '<complex_password>'; | |
# | |
# Grant select permissions on a table or view that you want to monitor: | |
# GRANT SELECT ON <schema>.<table> TO datadog; | |
# | |
# Grant permissions for a specific column on a table or view that you want to monitor: | |
# GRANT SELECT (id, name) ON <schema>.<table> TO datadog; | |
# | |
# Let non-superusers look at pg_stat_activity in a read-only fashon. |