January 13, 2015
#!/bin/sh PACKAGE=mypkg # set mode go test -coverprofile=coverage.out $PACKAGE go tool cover -func=coverage.out go tool cover -html=coverage.out # count mode go test -covermode=count -coverprofile=count.out $PACKAGE go tool cover -func=count.out go tool cover -html=count.out # more info: http://blog.golang.org/cover
go-lang (3) testing (2)
January 8, 2015
func log(s ...interface{}) { f, err := os.OpenFile("info.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { fmt.Printf("error opening log file: %v", err) os.Exit(1) } defer f.Close() log.SetOutput(f) ss := "" for _, p := range s { switch p.(type) { case bool: ss += fmt.Sprintf("%t ", p.(bool)) case int: ss += fmt.Sprintf("%d ", p.(int)) case float64: ss += fmt.Sprintf("%.2f ", p.(float64)) case string: ss += fmt.Sprintf("%s ", p.(string)) } } log.Println(ss) }
go-lang (3)
September 28, 2014
I don't play the lottery but I find random number generators and the Linux Kernel interesting so I wrote a simple Linux Kernel module that does a PowerballTM "quick pick". You can download it from GitHub: https://github.com/gdonald/linux-kernel-powerball-module
linux (8) kernel (4) module (1) powerball (1) lottery (1)
September 22, 2014
Ever want to know how to drop an argument (and value), --dir in this case, from a Bash script? Someone from my local LUG asked how to do it and this is what I came up with: Fun ;) #!/usr/bin/env bash args=("$@") myargs=() nextarg=-1 for ((i=0; i<$#; i++)) { if [ $nextarg == $i ]; then continue; fi case ${args[$i]} in --dir) nextarg=$((i+1)) ;; *) myargs+="${args[$i]} " esac } echo $myargs ./remove_dir.bash --dir foo --bar baz --bar baz
bash (2)
January 31, 2014
It doesn't seem you can lose data even when you might otherwise expect to ;)
I setup a small replica set using
mongod --fork --logpath a.log --smallfiles --oplogSize 50 --port 27001 --dbpath data/z1 --replSet z
mongod --fork --logpath b.log --smallfiles --oplogSize 50 --port 27002 --dbpath data/z2 --replSet z
mongod --fork --logpath c.log --smallfiles --oplogSize 50 --port 27003 --dbpath data/z3 --replSet z
And initalized it:
> rs.initiate(
{ _id:'z',
members:[
{ _id:1, host:'localhost:27001' },
{ _id:2, host:'localhost:27002' },
{ _id:3, host:'localhost:27003' }
]
}
);
Then I killed all three processes:
kill -9 25542 25496 25483
Next I brought one of them back up
mongod --fork --logpath c.log --smallfiles --oplogSize 50 --port 27003 --dbpath data/z3
and inserted a doc
> db.foo.insert({a:1})
Then I killed that process
kill -9 25885
and brought the replica set back online using
mongod --for
mongodb (1)
May 20, 2012
alias ls='ls -ah --color=always' alias ll='ls -lavh --color=always' alias cp='cp -i' alias vi='/usr/bin/emacs' alias ..='cd ..' alias ...='cd ../..'
bash (2)
April 24, 2012
If you want to leave Github for whatever reason, you probably want to take all your code with you, and all your history and branches, etc.
Here's an example for how I moved my Android Eclipse workspace from Github to my own remote server.
First I make a new git repo on my remote server:
$ git --bare init ~/git/workspace
The --bare option means I'm not going to work on the code in the remote git repo directly.
Next I push my current local 'master' to the new repo:
$ git checkout master
$ git push ssh://me@myserver.com/git/workspace master
After that I push my working branch:
$ git checkout work
$ git push ssh://me@myserver.com/git/workspace work
You could repeat this step if you have more branches.
I created my local repo using 'clone' so it has an 'origin' remote branch defined. This 'remote' branch is where git fetches and pushes changes.
Right now my 'fetch' and 'push' remote origins point to Github:
$ git remote -v
git@github.com:gdonald/workspace.git
git (3) github (1)
January 7, 2012
I had a problem with PostgreSQL pgdump recently. My setval() calls were all set to '1'. I whipped up this quick script to fix things: #!/usr/bin/env python DB_NAME = 'my_db' from subprocess import Popen, PIPE import re exclude = [ 'tablename', 'rows' ] tp = re.compile( '[^a-z_]' ) ts = Popen( [ "/usr/bin/psql", DB_NAME, "-c SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg_%' AND tablename NOT LIKE 'sql_%' ORDER BY tablename" ], stdout=PIPE ).communicate()[ 0 ].split( ' ' ) tables = [] for t in ts: t = tp.sub( '', t ) if len( t ) == 0 or t in exclude: continue tables.append( t ) for t in tables: sql = "SELECT pg_catalog.setval( pg_get_serial_sequence( '%s', 'id' ), ( SELECT MAX( id ) FROM %s ) + 1 );" % ( t, t ) print Popen( [ "/usr/bin/psql", DB_NAME, "-c %s" % sql ], stdout=PIPE ).communicate()[ 0 ]
postgresql (3) python (2)