Skip to content

Instantly share code, notes, and snippets.

View bitprophet's full-sized avatar
🎯
Focusing

Jeff Forcier bitprophet

🎯
Focusing
View GitHub Profile
# Bad
foo \
bar
# Good
foo \
bar
from fabric.api import parallel, execute, sudo
@parallel
def uptime():
sudo('uptime')
def do_my_stuff():
execute(uptime, hosts=['web1', 'web2'])

The setup:

  • Some top level tasks
  • A 'docs' submodule
  • docs.build is configured to be the default task for 'docs'
  • So, 'invoke docs' == 'invoke docs.build'. Either is allowed.

The question is, how should this setup display in --list? Our options:

  1. Fab 1.x style: display both, no indication of what maps to what:
@bitprophet
bitprophet / gist:5493982
Last active December 16, 2015 20:39
Descartes and external data sources

Cluster graphing

  • It's frequently useful to graph a metric over a cluster of hosts, e.g. "show me the number of requests/s being handled by all of my load balancers".
  • Doing this in vanilla Graphite is easy - it honors both glob expressions (lb*) and brace expressions ({a,b,c,d}).
  • But how do we generate these for clusters whose hostnames don't glob well, and/or whose members change over time?

Descartes

  • Generally flippin' awesome.
  • Has a database of Metrics, Graphs composing 1+ Metrics, and Dashboards composing 1+ Graphs.
@bitprophet
bitprophet / wat.md
Last active December 17, 2015 00:29
The problem with unittest

(Using fabric/fabric as an example of a unittest style project with a complex, nontrivial test suite)

» find tests -type f -maxdepth 1 -mindepth 1 -name "*.py" | wc -l
    18
» find tests -type f -maxdepth 1 -mindepth 1 -name "test_*.py" | wc -l
    13

75% of the files in my tests folder are tests, yet they must be named test_.

» grep -inr "class " tests/test_* | wc -l

  1. The code will get better. Linus' Law: "given enough eyeballs, all bugs are shallow": we'll be able to get community contributions and bug reports, and thus the code will grow better faster than we can grow it ourselves. Also, Joy's Law - "No matter who you are, most of the smartest people work for someone else": we'll get better code from people who don't work for us than from people who do.

  2. We'll write better code. Wall's 3rd great virtual of a programmer, Hubris: we'll write better code when we don't want other people to say bad things about us. We'll do better with the world watching than with just us.

  3. Increased ability to hire. We're a 19k circ newspaper in a town most people have never heard of. Open source will help put us on the map, make us a place people actually might be interested in working.

  4. When we do hire, we'll be able to hire peop

» inv -h test
Usage: inv[oke] [--core-opts] test [--options] [other tasks here ...]
Docstring:
Run a Spec or Nose-powered internal test suite.
Options:
-m STRING, --module=STRING Just runs tests/STRING.py.
-r STRING, --runner=STRING Use STRING to run tests instead of 'spec'.
» python2.6 -c "print 3/2"
1
» python3 -c "print(3/2)"
1.5
#!/usr/bin/env ruby
# Parse changelogs per branch
changelogs = {}
# Start at 1.2 because we don't have 1.1.0 in the new format. NBD, 1.1 is old
# as shit anyway.
releases = 2.upto(7).map {|x| "1.#{x}"}
target = /\* :(?<type>feature|bug|support|release):`((?<issue_no>\d+)|(?<release_no>\S+) <[^>]+>)`/
releases.each do |x|
changelogs[x] = `git show origin/#{x}:docs/changelog.rst`.split(/\n/).map do |line|