Skip to content

Instantly share code, notes, and snippets.

@knowsuchagency knowsuchagency/readme.md
Last active Oct 19, 2018

Embed
What would you like to do?
TruSTAR questionnaire answers

Achievement

One of the things I'm most proud of is the long-term impact I had while working at the NSA -- organizationally, culturally, and pedagogically. When I arrived there and began working as an analyst, the civilian software engineers would build tools for analysts, and those active-duty analysts would use those tools to do their work. Because of cultural differences between federal civilians and military personnel and the way the engineering and analytics are treated as orthogonal to one-another organizationally, there was very little communication between the two teams.

Once I started working as part of the engineering team, I helped bridge that gap in communication between engineering and analysts. In fact, that collaboration was so successful, NSA Hawaii made it a point to create a new role within engineering specifically for a military analyst to work as a software developer and began creating a training pipeline for the role as I was leaving.

Recent book and why one should read it

Code: The Hidden Language of Computer Hardware and Software by Charles Petzold

This book brilliantly illustrates the history of computing from first-principles. You actually get a sense that you could build a computer from scratch at the end of the book as the author not only explains the electricity, electronics, logic, and algebra that allow computers to work, but the intuitions that lead to the development of each of those disparate ideas. It's not only the breadth and depth of the work that's impressive to me, the way the book makes all those concepts accessible is what I love about it. Anyone with an interest in how computers work and the history and intuitions that lead to their invention would be well-served by reading this book.

Mentorship

At the time I was working as a developer for NSA in Hawaii, I started the Python User Group, PyHawaii. I was really fortunate to be working under some extremely intelligent people at the time, and I wanted to be able to share that knowledge with other people. It was incredibly rewarding to encounter familiar faces week-after-week at our meetup, helping them learn how to program and seeing their progress over time. One of the things I learned in my own experience mentoring is not trying to make something out to be inherently simple or straightforward, because people learn at different paces. If you say something like, "And so you see, recursion is really simple..." and someone doesn't feel that way, they may come to think it's because they're not capable of understanding the subject i.e. have a fixed mindset about it. I often caveat what I say with statements like, "It's ok if you don't get it the first time; it might help to learn the material from other sources as well. It can help to get different explanations from different people and this can take some time to sink in."

Classes

I wrote this simple class diagram for how I imagine WhatsApp might structure their classes on iOS. I imagine one of the most challenging aspects would be caching messages and achieving eventual consistency for the conversations had among multiple clients across disparate networks.

Here is a link to the image as well as a link to the sketchboard on which I created it

Flattening

Here's the code for how I would write a function that flattens an array of integers. I would likely have the tests written in pytest in a separate module, but I hope this is sufficiently illustrative.

import pytest


def flatten(numbers):
    """
    Return a flattened list of integers from a potentially nested list.

    >>> flatten([1, 2, [3, [4, 5]], 6])
    [1, 2, 3, 4, 5, 6]

    >>> flatten([])
    []

    >>> flatten(lambda: None)
    Traceback (most recent call last):
     ...
    ValueError: Expected list. numbers arg is of type <class 'function'>

    Args:
        numbers: a (potentially nested) list of numbers

    Returns: a flat list of integers
    """
    if not isinstance(numbers, list):
        raise ValueError(f'Expected list. numbers arg is of type {type(numbers)}')

    def inner_generator(numbers):
        """A generator that yield elements from a list of numbers."""
        for element in numbers:
            if isinstance(element, list):
                yield from inner_generator(element)
            elif isinstance(element, int):
                yield element
            else:
                raise ValueError(f'Expected integer or list. '
                                 f'Got element {element} of type {type(element)}')

    return list(inner_generator(numbers))


def test_flatten_on_empty_list():
    assert flatten([]) == []


def test_flatten_on_valid_input():
    assert flatten([1, 2, [3, [4, 5]], 6]) == [1, 2, 3, 4, 5, 6]


def test_flatten_raises_valueerror_on_invalid_input():
    with pytest.raises(ValueError):
        flatten([3.14])
        flatten(["hello, world"])
        flatten({})
        flatten(lambda: None)


if __name__ == '__main__':
    # call pytest on this module; include doctests
    pytest.main(['--doctest-modules', __file__])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.