Skip to content

Instantly share code, notes, and snippets.

View artyom's full-sized avatar

Artyom Pervukhin artyom

View GitHub Profile
@artyom
artyom / README.md
Created January 12, 2015 15:26
Watch which nginx http endpoints are hit

Save code to filter.awk, do chmod +x filter.awk, then watch which endpoints (w/o params) get hit:

tail -f /var/log/nginx/access.log | ./filter.awk
@artyom
artyom / self-logging.sh
Created November 29, 2014 11:37
Redirect script output to syslog from within script itself
#!/bin/sh -eu
LOGPIPE=/tmp/logpipe.$$
mkfifo $LOGPIPE
logger -t "$0.$$" -f $LOGPIPE &
exec 1>$LOGPIPE
exec 2>&1
rm -f $LOGPIPE
echo "hello on stdout"
echo "hello on stderr" >&2
exec sleep 20
@artyom
artyom / skype-analyze.go
Created November 9, 2014 17:14
Program to calculate total month call duration from skype csv detail files
package main
import (
"encoding/csv"
"fmt"
"io"
"log"
"os"
"time"
)
@artyom
artyom / conf.go
Created October 27, 2014 18:54
Apply options from configuration file given by command line flag, then override it with another command line flags.
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"github.com/artyom/autoflags"
@artyom
artyom / pg-json-select.go
Created August 7, 2014 09:03
Unmarshal Postgresql's json type in Go
package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
_ "github.com/lib/pq"
)
package main
import (
"database/sql"
"errors"
"fmt"
_ "github.com/bmizerany/pq"
"os"
"regexp"
"strings"
@artyom
artyom / result.txt
Created July 10, 2014 14:39
Golang XOR performance for 8/64 bytes long integers
$ go test -bench .
PASS
Benchmark8 1000000 1093 ns/op 936.69 MB/s
Benchmark64 20000000 134 ns/op 7603.74 MB/s
ok _/private/tmp/x 3.944s
@artyom
artyom / gist:927134f52032d79162b5
Created May 21, 2014 15:47
runit, runsv: detach old service, run new one
# find /etc/sv/foo -type f -executable -print0 | xargs -r0 awk 'FNR==1{print "\n$ cat ", FILENAME}{print}'
$ cat /etc/sv/foo/log/run
#!/bin/sh -eu
exec 2>&1
LOGDIR=/tmp/foo-log
test -d $LOGDIR || mkdir -p $LOGDIR
exec svlogd $LOGDIR
$ cat /etc/sv/foo/run
@artyom
artyom / t.go
Created May 16, 2014 05:39
Go flag supports both 'long' and 'short' options
package main
import (
"flag"
"fmt"
)
func main() {
n := 42
flag.IntVar(&n, "num", n, "your number ('long' option)")
@artyom
artyom / rex.go
Last active June 4, 2016 17:19
Prototype: execute commands via ssh on multiple hosts in parallel, using ssh-agent for authentication
package main
import (
"bufio"
"flag"
"fmt"
"io"
"log"
"net"
"os"