This Gist contains source code for my blog article "BlazingMQ: Hands On". See the article for more explanation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro plural(num, unit) -%} | |
{{ num }} {% if num == 1 %}{{ unit }}{% else %}{{ unit }}s{% endif -%} | |
{%- endmacro %} | |
{% macro ordinal(number) -%} | |
{%- if number % 100 > 3 and number % 100 < 21 -%}{{ number }}th | |
{%- elif number % 10 == 1 -%}{{ number }}st | |
{%- elif number % 10 == 2 -%}{{ number }}nd | |
{%- elif number % 10 == 3 -%}{{ number }}rd | |
{%- else -%}{{ number }}th{%- endif -%} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import logging | |
import logging.config | |
import logging.handlers | |
import os | |
import sys | |
from typing import Any |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import asyncio | |
import sys | |
class ChatServer: | |
def __init__(self, server_name, port, loop): | |
self.server_name = server_name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import select | |
import signal | |
import subprocess | |
import time | |
class ProcPoller(object): | |
"""Watches multiple processes for output on stdout and stderr.""" | |
def __init__(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <stdlib.h> | |
namespace { | |
static const char * const DIGITS = "0123456789"; | |
} | |
/// Use with std::sort(start, end, NaturalComparator()) | |
class NaturalComparator | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import * | |
from random import * | |
from turtle import * | |
def grass(): | |
color("ForestGreen") | |
begin_fill() | |
forward(5000) | |
for i in range(3): | |
right(90) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import * | |
from random import * | |
from turtle import * | |
def tree(branchLen): | |
old_color = color() | |
old_width = width() | |
if branchLen >= 20: | |
color("brown") | |
width(branchLen / 5.0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def toposort(data): | |
"""Argument is a dict mapping element to set of dependency elements. | |
Generator yields sets of elements in an appropriate order to satisfy | |
dependencies. Each element in the set from a single iteration may be | |
processed in parallel (i.e. they have no dependencies between them). | |
""" |