Skip to content

Instantly share code, notes, and snippets.

View axw's full-sized avatar

Andrew Wilkins axw

View GitHub Profile
@axw
axw / main.go
Last active August 29, 2015 14:09
Coverage testing of "main" program
package main
import "flag"
var b = flag.Bool("myflag", false, "description")
func main() {
flag.Parse()
if *b {
println("true")
@axw
axw / linesmatch.go
Created September 15, 2015 02:54
gocheck checker for multiple single-line regexps operating on multiple line output
var LinesMatch gc.Checker = &linesMatchChecker{
&gc.CheckerInfo{Name: "LinesMatch", Params: []string{"obtained", "regexps"}},
}
type linesMatchChecker struct {
*gc.CheckerInfo
}
func (linesMatchChecker) Check(params []interface{}, names []string) (result bool, error string) {
obtainedLines := strings.Split(params[0].(string), "\n")
@axw
axw / add_logging.py
Created October 7, 2011 03:26
Automatically add logging to top-level functions with cmonster
import cmonster
import cmonster.ast
import sys
parser = cmonster.Parser(
"test.cpp",
data="""\
#include <stdio.h>
int main(int argc, const char *argv[])
{
@axw
axw / YieldUntilAllOtherBlock.go
Created May 1, 2012 07:26
YieldUntilAllOtherBlock
package main
import (
"fmt"
"os/exec"
"runtime"
"strings"
"syscall"
)
@axw
axw / remote_import.py
Created November 23, 2012 01:14
Remotely import a local package with Pushy
import pushy
# Load the local package into a "PushyPackageLoader". This takes care of loading package
# sources and crafting them into a structure that can be loaded by "InMemoryImporter".
import whatever
loader = pushy.client.PushyPackageLoader()
packages = loader.load(whatever)
with pushy.connect("ssh:remotehost") as conn:
remote_importer = conn.modules.pushy.client.InMemoryImporter(*packages)
@axw
axw / local_import.py
Created November 23, 2012 09:00
Locally import a remote package with Pushy
import pushy
import sys
with pushy.connect("ssh:remotehost") as conn:
whatever = conn.modules.whatever
loader = conn.modules.pushy.client.PushyPackageLoader()
packages = loader.load(whatever)
importer = pushy.client.InMemoryImporter(*packages)
sys.meta_path.insert(0, importer)
@axw
axw / juju-coverage.bash
Created November 26, 2015 07:15
Recursively run tests with coverage profiling of all juju packages, then output a gocov profile
#!/bin/bash
set -e
tmp=$(mktemp -d -p "" gocov.XXXXXXXXXX)
function cleanup {
rm -rf "$tmp"
}
trap cleanup EXIT
@axw
axw / authorized_key.go
Created December 18, 2013 01:55
Translate PEM key to authorized_key
package main
import (
"fmt"
"io/ioutil"
"log"
"code.google.com/p/go.crypto/ssh"
)
@axw
axw / keybase.md
Last active February 7, 2016 12:32

Keybase proof

I hereby claim:

  • I am axw on github.
  • I am axw (https://keybase.io/axw) on keybase.
  • I have a public key ASCx6q32COJmBADGwDpZt1bGvOZ8lOLsBMFepUH8EMr0qAo

To claim this, I am signing this object:

package main
import (
"fmt"
"io"
"regexp"
"strings"
"github.com/lestrrat/go-jsschema"
)