Skip to content

Instantly share code, notes, and snippets.

@blakesmith
blakesmith / lein.clj
Created April 23, 2012 21:05
Leiningen install crate
(ns pallet.crate.lein
(:require [pallet.action.remote-file :as remote-file]))
(def default-install-path "/usr/local/bin")
(def script-url "https://raw.github.com/technomancy/leiningen/stable/bin/lein")
(defn- install-script
[session install-path]
(-> session
(remote-file/remote-file
@blakesmith
blakesmith / fr.sh
Created April 24, 2012 15:46
Rails global find/replace
export search="Find string"
export replace="Replace string"
grep -l -R $search app spec lib | xargs sed -i -e "s/$search/$replace/g"
find . -name "*-e" | xargs rm
@blakesmith
blakesmith / gist:3049248
Created July 4, 2012 19:55
Go Tour: Exercise: Loops and Functions - My solution
package main
import (
"fmt"
"math"
)
func newtAppx(x float64, appx float64) float64 {
return appx - ((math.Pow(appx, 2.0) - x) / (2 * appx))
}
@blakesmith
blakesmith / gist:3049269
Created July 4, 2012 20:04
Go Tour: Exercise: Exercise: Maps - My solution
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
counts := make(map[string]int)
splitStrings := strings.Split(s, " ")
@blakesmith
blakesmith / gist:3051547
Created July 5, 2012 05:27
Go Tour: Exercise: Exercise: Slices - My solution
package main
import "code.google.com/p/go-tour/pic"
func imageFun(x, y int) uint8 {
return uint8(x) ^ uint8(y)
}
func Pic(dx, dy int) [][]uint8 {
image := make([][]uint8, dx)
@blakesmith
blakesmith / gist:3051584
Created July 5, 2012 05:44
Go Tour: Exercise: Exercise: Fibonacci closure - My solution
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
a := 0
b := 1
f := func() int {
package main
import (
"net/http"
"log"
"io/ioutil"
"fmt"
)
func main() {
@blakesmith
blakesmith / grok_test.c
Created August 26, 2012 23:53
Simple Grok test. Compile with: gcc grok_test.c -Wall -lgrok -o grok_test
USERNAME [a-zA-Z0-9_-]+
USER %{USERNAME}
INT (?:[+-]?(?:[0-9]+))
BASE10NUM (?<![0-9.+-])(?>[+-]?(?:(?:[0-9]+(?:\.[0-9]+)?)|(?:\.[0-9]+)))
NUMBER (?:%{BASE10NUM})
BASE16NUM (?<![0-9A-Fa-f])(?:[+-]?(?:0x)?(?:[0-9A-Fa-f]+))
BASE16FLOAT \b(?<![0-9A-Fa-f.])(?:[+-]?(?:0x)?(?:(?:[0-9A-Fa-f]+(?:\.[0-9A-Fa-f]*)?)|(?:\.[0-9A-Fa-f]+)))\b
POSINT \b(?:[0-9]+)\b
WORD \b\w+\b
[root@host bsmith]# traffic_line -r proxy.config.cache.ram_cache.size
32212254720
[root@host bsmith]# traffic_line -r proxy.process.cache.bytes_total
0
[root@host bsmith]# traffic_shell
Successfully Initialized MgmtAPI in /var/trafficserver/trafficserver
% trafficserver> show:cache-stats
Bytes Used --- 0 GB
Cache Size --- 0 GB
package main
import (
"bytes"
"code.google.com/p/go.net/websocket"
"crypto/sha1"
"fmt"
"image/gif"
"image/png"
"io"