Skip to content

Instantly share code, notes, and snippets.

@alq666
alq666 / wc.go
Created December 25, 2012 23:56
package main
import (
"tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
result := make(map[string]int)
package main
import "tour/pic"
func Pic(dx, dy int) [][]uint8 {
m := make([][]uint8, dy, dy)
for i := 0; i < dy; i++ {
m[i] = make([]uint8, dx, dx)
for j := 0; j < dx; j++ {
m[i][j] = uint8((i+j)/2)
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
i, j := 0, 1
return func() int {
i, j = j, i+j
package main
import "fmt"
import "math/cmplx"
const d float64 = 0.0001
func Cbrt(x complex128) complex128 {
z0, z := complex128(0), complex128(1)
for cmplx.Abs(z - z0) > d {
@alq666
alq666 / upgrade-chef.sh
Last active December 10, 2015 09:58
Replace chef packages
sudo sed -i 's/lucid/lucid-0.10/' /etc/apt/sources.list.d/opscode.list && sudo apt-get update && sudo apt-get dist-upgrade -y
@alq666
alq666 / support_ctf.rb
Last active December 10, 2015 18:58
A simple coding test for the Support Engineer position at http://jobs.datadoghq.com
require 'rubygems'
require 'dogapi'
# Create a simple client
# You typically want to do:
# Dogapi::Client.new(your_actual_api_key_as_a_string, ...)
dog = Dogapi::Client.new(YOUR_API_KEY_HERE)
# Emit a list of points in one go as a list of (timestamp, value)
# here we pretend to send a point a minute for the past hour

Linux System Metrics

CPU

  • system.cpu.idle: % Idle CPU
  • system.cpu.system: % System CPU
  • system.cpu.user: % User CPU

Disk

Linux System Metrics

CPU

  • system.cpu.idle: % Idle CPU
  • system.cpu.system: % System CPU
  • system.cpu.user: % User CPU

Disk

@alq666
alq666 / gist:4600033
Created January 22, 2013 23:47
Slow mcnulty queries
gawk '/batch_query.*slow/ {d = substr($(NF-1), 3, length($(NF-1))-3); if (d > 5) {print $1, d, $7, $8}}' /mnt/log/mcnulty/dogweb.log
@alq666
alq666 / unix.py.diff
Created January 29, 2013 04:23
To fix a locale issue
diff --git a/checks/system/unix.py b/checks/system/unix.py
index 5ebc6b2..8be6c5c 100644
--- a/checks/system/unix.py
+++ b/checks/system/unix.py
@@ -626,7 +626,7 @@ class Cpu(Check):
def get_value(legend, data, name):
"Using the legend and a metric name, get the value or None from the data line"
if name in legend:
- return float(data[legend.index(name)])
+ return float(data[legend.index(name)].replace(",", "."))