Tuesday, August 23, 2016

Saturday, August 6, 2016

TIP: find specific Docker container without using "cut" or other Shell silliness

People on the Interwebs love doing things in a leaden, verbose, laborious, and dusty manner.  Like piping a command through egrep then cut and sed then awk, when just "awk" will do.

Take Docker. We often want to find out which container is running something specific. Once we find our container, we want to "exec" a shell into it, or we want to kill it.

Here's the best way that doesn't mess with cut/sed/awk:

$ docker ps --filter ancestor=web,status=running --quiet
8fbc117716c3

In the previous command I was looking for the container ID that is descended from my "web" image. I'm not interested in my database nor Redis nor anything else, I want my web container.

Here's how to use it in practice, by killing the web container:

$ docker rm -f $(docker ps --filter ancestor=web,status=running --quiet)
8fbc117716c3

Also, here's how to use the same technique to hop into the web container, and run a shell.  This I use constantly, so I can examine a container to see what's going on, what it's doing, or what it's not doing:

$ docker exec -it $(docker ps --filter ancestor=web,status=running --quiet) bash
root@23b5a26eb252:/#

TIP: use YouTube to learn quickly

I'm learning lots of Amazon Web Services topics via videos on YouTube.  There's a lot of material, but I can absorb the content faster than people speak.  Also, I often want to go back and listen to what they say a few times.

I use these YouTube keyboard shortcuts ALL the time:

space -- play/pause
f/esc -- enter/leave full screen mode
left/right arrows -- go back/forwards five seconds
</> -- slower/faster

We also have these keys:

up/down arrows -- increase/decrease volume
0-9 -- jump to spot in video, 0=beginning

It's really freeing to learn material 150% or 200% faster using these keyboard shortcuts.  Enjoy!

(Thanks to University of Michigan)

Friday, July 29, 2016

TIP: running 2N+1 Gunicorn workers

If you read, people tend to say that for web services, run 2N+1 workers, where N is the number of CPUs.

It turns out the Intarwebs are wrong about exactly how to do this. Here's my solution based on "epicbrew"'s work on Stack Overflow:

gunicorn --workers=$((2 * $(getconf _NPROCESSORS_ONLN) + 1)) wsgi:application
The cool thing is that it works on both macOS and Linux!

Thursday, July 28, 2016

pragmatic Test Driven Development

As a dev, I write mostly unit tests and care about test coverage increasing over time.  My view has shifted recently.

Although web UI tests can be fragile, they present a lot of bang for the buck, coverage-wise.  It turns out they also have a lot of unique business value; that is, if we're testing what our users see, then when we change something we can immediately know that business value is being affected.

- I recommend view-level tests. Django directly supports and advocates this style. They're fast and easy to create like Unit tests, but have direct user-level (thus business-level) value.

- for UI tests, set an ID on everything that you are testing. (Never ever use XPath.)  This makes UI tests more durable and reliable. 

- Kent Beck has been the main proponent of TDD from the very beginning, as part of Extreme Programming. “I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence”

- I really enjoy Brian Okken's entirely pragmatic view on testing:
My reaction to “Is TDD Dead?”  His podcast is in my Top 3: Python Testing