Skip to content

Instantly share code, notes, and snippets.

View defp's full-sized avatar

lidashuang defp

View GitHub Profile
@defp
defp / binary_tree.go
Created February 15, 2014 18:59
go run binary_tree.go
package main
import (
"fmt"
)
type Tree struct {
Value int
Left, Right *Tree
}
@defp
defp / metrics.go
Created March 25, 2014 02:21
influxdb with go-metrics
package main
import (
"log"
"math/rand"
"runtime"
"time"
// "github.com/rcrowley/go-metrics"
// "github.com/rcrowley/go-metrics/influxdb"
/** @scratch /configuration/config.js/1
* == Configuration
* config.js is where you will find the core Grafana configuration. This file contains parameter that
* must be set before Grafana is run for the first time.
*/
define(['settings'],
function (Settings) {
"use strict";
return new Settings({
@defp
defp / slice_array1.go
Last active August 29, 2015 14:00
不对slice类型的参数进行append
package main
import (
"fmt"
)
func operatSlice(s []int, num int) []int {
for i := 0; i < num; i++ {
s = append(s, 4)
}
@defp
defp / test.exs
Created May 2, 2014 12:46
elixir pipe test
defmodule Hello do
def pipe(a, b) do
IO.puts a
IO.puts b
end
end
"hello" |> Hello.pipe("world")
-module(kvs).
-export([start/0, store/2, lookup/1]).
start() -> register(kvs, spawn(fun() -> loop() end)).
store(Key, Value) -> rpc({store, Key, Value}).
lookup(Key) -> rpc({lookup, Key}).
rpc(Q) ->
kvs ! {self(), Q},
receive
defmodule Kvs do
def store(key, value) do
rpc({:store, key, value})
end
def start do
Process.register spawn(fn -> loop() end), :kvs
end
def lookup(key) do
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
package main
import (
"bufio"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"