Skip to content

Instantly share code, notes, and snippets.

View mjs's full-sized avatar
💭
curl -s http://104.196.37.21/|grep -Eo '^\S+'

Menno Finlay-Smits mjs

💭
curl -s http://104.196.37.21/|grep -Eo '^\S+'
View GitHub Profile
#!/usr/bin/python3.5
import asyncio
import logging
from juju import loop
from juju.model import Model, ModelObserver
class ModelWatcher(ModelObserver):
package main
import (
"fmt"
"github.com/juju/juju/api"
"github.com/juju/juju/juju"
"github.com/juju/juju/jujuclient"
"github.com/juju/juju/state/multiwatcher"
)
@mjs
mjs / fib.rs
Created August 25, 2017 01:54
Fibonacci sequence generation done in 3 ways using Rust
const ITERS: usize = 20;
fn print_fib(n: usize) {
let mut x = (1, 1);
for i in 0..n {
println!("{}: {}", i, x.0);
x = (x.1, x.0 + x.1)
}
}
@mjs
mjs / example.go
Last active August 18, 2020 02:25
Example of github.com/pkg/errors
package main
import (
"fmt"
"github.com/pkg/errors"
)
func A() error {
// New errors created with pkg/errors.New() will include a full
@mjs
mjs / perf_test.go
Last active October 17, 2017 00:26
Benchmarks of various ways to format to []byte("prefix label1=int1 label2=int2...") byte slices.
package perf_test
/*
Results on my machine:
BenchmarkSprintf-4 5000000 337 ns/op
BenchmarkBuffer-4 5000000 283 ns/op
BenchmarkManualAppend-4 20000000 91.0 ns/op
BenchmarkLineBuilder-4 10000000 182 ns/op
package b
import (
"bytes"
"testing"
)
var needsEscape = []byte(`foo\ bar\"sne`)
func BenchmarkOrig(b *testing.B) {
package perf_test
import (
"bytes"
"fmt"
"strconv"
"testing"
)
var (
@mjs
mjs / slow-influxd.go
Created April 24, 2018 11:01
A fake influxd that is slow to respond
package main
import (
"fmt"
"log"
"net/http"
"time"
)
import "flag"
@mjs
mjs / sshj
Created August 1, 2018 03:21
SSH jump host helper
#!/bin/sh
if [ $# -ne 2 ]; then
echo "usage: sshj <jump_host> <target>"
exit 1
fi
exec ssh -o ProxyCommand="ssh -W %h:%p $1" "$2"
@mjs
mjs / scpj
Created August 1, 2018 23:22
Helper for using scp through a jump host
#!/bin/sh
if [ $# -lt 3 ]; then
echo "usage: sshj <jump_host> <source> <target>"
exit 1
fi
jump=$1
shift