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
@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
@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 / 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)
}
}
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"
)
#!/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/api/controller"
"github.com/juju/juju/juju"
"github.com/juju/juju/jujuclient"
"github.com/kr/pretty"
imap = imapclient.IMAPClient(server)
imap.login(username, getpass())
imap.select_folder('INBOX')
messages = imap.search(['NOT', 'DELETED'])
for message_id, data in imap.fetch(messages, ['RFC822']).iteritems():
body = data['RFC822']
# do stuff with message_id and body...
package main
import (
"fmt"
"net/http"
"net/url"
"sync"
)
type ProxyConfig struct {
import time
from logging import getLogger
from logging.handlers import SysLogHandler
logger = getLogger()
logger.addHandler(SysLogHandler("/dev/log"))
while True:
print time.asctime()
logger.error("x" * 200)
@mjs
mjs / juju-db
Last active September 1, 2016 21:56
Helper to get a MongoDB shell on a Juju controller
#!/bin/bash
model=${1:-controller}
machine=${2:-0}
read -d '' -r cmds <<'EOF'
password=`sudo grep oldpassword /var/lib/juju/agents/machine-*/agent.conf | cut -d' ' -f2`
/usr/lib/juju/mongo*/bin/mongo 127.0.0.1:37017/juju --authenticationDatabase admin --ssl --sslAllowInvalidCertificates --username "admin" --password "$password"
EOF