Maia McCormick

Programmer, writer, nerd

Hi, my name is Maia 👋🏻 and I'm a programmer based in New York City. This website is where I (somewhat infrequently) chronicle my journeys through code, as well as other vaguely related adventures.

Nested Functions

python recurse center tech

Know what’s cool? Nested functions.

The other day, as I was making this craaaazy dance parser (that’s getting more and more convoluted by the minute), Alan suggested a really baller way of organizing it: using a bunch of little mini-parser functions that all look for something specific in your text, and smooshing related parsers together into one macro-parser that runs all of them in turn until one returns something. In Alan’s lovely mock-up code that I’m shamelessly copying over here, that might look like this:

def contains_an_a(input):
    return input.find("a") > -1

def contains_a_b(input):
    return input.find("b") > -1

def one_of(parsers):
    def parser(input):
        for p in parsers:
            result = p(input)
            if result:
                return result
    return parser

contains_an_a_or_a_b = one_of([contains_an_a, contains_a_b])

The handy thing about having all of these bite-size functions is that none of them gets too crazy bulky, and also, since they’re functions (and not dicts like I was using earlier), I can use regexes in them! I’m also jamming on the idea of passing functions to other functions, so I made an even bigger function called use_parser that takes a parser, a default value, and an ‘ask’, which it uses to ask the user (via raw_input) what the value should be. This way, I can take a single parser and customize it in a variety of ways. Say for example I have a distance parser: for do-si-dos and gypsies it should default to False (because those moves don’t necessarily need to take a distance) and for allemandes it should ask the user, “what’s the value of ‘dist’ here?”

Slicing Is Not Enough (or, Adventures in Deep Copy)

python recurse center tech

The sudoku solver that I’m working on with Miriam was nearly finished before it started when we were playing around with ways to draw a board to terminal. I came to the table with some initial code I had written—

def draw_board(board):
    for i in range(0,9):
        board[i].insert(6, "|")
        board[i].insert(3, "|")
        row_string = "  ".join(map(str, board[i]))
        if i in [2, 5]:
            print row_string
            print "________________________________"
        else:
            print row_string

def newboard():
    return [[0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0]]

and the shiny output!

>>> myboard = newboard()
>>> draw_board(myboard)

0  0  0  |  0  0  0  |  0  0  0
0  0  0  |  0  0  0  |  0  0  0
0  0  0  |  0  0  0  |  0  0  0
________________________________
0  0  0  |  0  0  0  |  0  0  0
0  0  0  |  0  0  0  |  0  0  0
0  0  0  |  0  0  0  |  0  0  0
________________________________
0  0  0  |  0  0  0  |  0  0  0
0  0  0  |  0  0  0  |  0  0  0
0  0  0  |  0  0  0  |  0  0  0

Everything was awesome! Or so I thought. But look what happened when I ran the code again.

Checking in With the Hacker School Experience

recurse center

Oh hai there, blag! It’s been a while. Too long. The days here blur together occasionally—hours of staring a screen working on multiple only-slightly-different problems will do that to you, and it’s really easy to lose track of what you’ve been working on, accomplishing, learning, and thinking about. Especially when those accomplishments seem really tiny and mundane. (“Yay, I got my database search page to work! Yay, I got my database search page to work for two things in sequence! Wait, it’s 7:00?”)

Had a one-on-one with Allison this afternoon about the State of the Hack so far—how HS is treating me, what I might want to do differently, what I might want to be different about the environment. Here are some thoughts prompted by that conversation.

  • I want to get better at asking for help, surmounting impostor syndrome, etc. I’m pretty good at this, all things considered, but I still need to do lots more work on this front. Sometimes asking a question on a Zulip thread isn’t what I need—it happens to not get responded to, or (more often) I would benefit much more from discussing it in person.
  • An interesting thing about the HS environment is how it’s way more normal to Zulip someone from across the room than go over and tap them on the shoulder. Generally, I get way more out of an in-person conversation than an online one, so I’d like to be better about just finding people in person to ask them questions. (Of course, the benefit of Zulip-ing is that you know who can/can’t be interrupted. Tricky balance here. But I should feel more able to approach facilitators, at least.)

Fluffy (and Often Queer/YA/Both) Book Recs

books

In response to a recent Hacker School discussion about fluffy book recommendations written by !(white & cis-male), here’s a list of some of my go-to’s, and books I’ve enjoyed reading lately. What defines fluff? That’s a more complicated question for a later time. How I’ve been thinking of it lately is as books that don’t require much effort to read/parse—i.e., not an awful lot of subtext, relatively simple language and not too much artistry of the obfuscating variety in the text itself—that play off characters and tropes that we like to read about. They will generally have not-terribly-well-developed characters, characters that are easy to identify with, and the stories and happy endings that we want for ourselves. But, regardless of my definitional musings, here are some books! And so, in no particular order:

  • Annie on My Mind by Nancy Garden: LOVE. I think it was the first bit of lesbian lit that I read, and thus holds a special place in my heart.
  • The Miseducation of Cameron Post, by Emily M. Danforth: follows a young girl’s sexual self-discovery, first love(s), and her time at a homosexual rehabilitation program.
  • Beautiful Game and Solstice by Kate Christie: fluff in the highest degree, but well-written, engaging, hold-your-attention-till-the-very-end fluff. (I also think it’s worth noting that I typed the title to the first as “Beautiful Gayme” the first time through. Oops…)
  • Anything by Tamora Pierce, but especially the Song of the Lioness quartet: because Tamora Pierce is the bomb, and has an incredible gift for plots, and has been the beginning of more girls’ feminism than can be counted. Feminist, sex-positive, swords-and-sorcery high fantasy at its best!

'Wasting' Time?

recurse center writing about coding

At Hacker School today, I didn’t get all that much done, and in my day’s worth of non-progress I brushed up against two distinct kinds of “wasted” time.

The first is somewhat productive, as wasted time goes. I spent most of the afternoon barking up various wrong trees as I tried to figure out how to structure the next step of my current project (a contradance database, which I’m sure I’ll blog about for real soon). Kind of like a real-life breadth-first search where every node takes several hours.

I’ve got a way to structure my data, and now I want to be able to search and sort and filter a bunch of these data-bundles. First I assumed I’d write the search code in Python and worry about making it web-app-y later. I started brainstorming and had no idea how I would optimize my code, and then someone suggested I use Data Tables a JQuery plug-in which will search and sort data super fast. So I spent a while reading up on Data Tables, looking through FAQs and add-ons and trying to figure out if it would give me some of the more advanced searching functionality I wanted. Someone else then suggested that if I ultimately wanted to search by a giant table of data invisible to the user, why don’t I just use mySQL and go right to the database end of things? So I talked to Andrew and hashed out a vague plan and set up mySQL on my machine and found some nice-looking tutorials… only to have someone else point out that hey, you don’t need to worry about learning SQL, Django can do all of that for you and you still get to write in Python. I gave Django a quick look, got excited, and then whoops it was 5:00.

When Is It Time to Give Up?

recurse center

I had this grand, exciting plan. A normal Markov generator trains on a corpus of text, and sees what words are likely to come after other words. So for example, given “Happy families are all alike,” it would say, “Happy families” —> “are”, “families are” —> “all”, “are all” —> “alike”. You can then start with any random seed and populate a whole chunk of however much text you please by going through your correspondence and picking at random: “hmm, what words might possibly come after ‘are all’?”

I was going to take it one step further and incorporate part-of-speech tagging. The above example sentence would be part-of-speech tagged, “adjective/plural noun/verb non-3rd person singular present/determiner/adverb.” Then I could make a correspondence: adjective + plural noun may be followed by a non-3rd person singular present verb, and so on. And when I had a whole paragraph or two worth of “adjective noun verb” etc. I could begin to fill that in from my word correspondence: “What word might come after ‘families are’ that is also a noun?”

It was brilliant! I was excited! And, as you’ve probably guessed, things didn’t turn out the way I had planned. I didn’t quite consider that one of my correspondences was much more general than the other, so is I generated my parts-of-speech beforehand and then went looking for a word that can follow words a + b and is also a (fill in part of speech here), I wouldn’t necessarily find anything! And then I’m reduced to filling in a random (part of speech), which leaves me no better off than a normal Markov generator, and perhaps even worse (see my last two posts for comparison).

Not Sure if My Smarter Markov Generator Is Better or Worse...

recurse center

Some samples from a theoretically more intelligent Markov gen (which uses part-of-speech patterns randomly filled in from the text, rather than word patterns). Though honestly, this one seems a fair bit worse than the “dumb” one. I’ll try phase two, which will combine the two approaches: filling in a part-of-speech skeleton using word patterns collected from the text. Anyway, here’s some gobbledygook!

Psuedo-Harry Potter and the Chamber of Secrets

‘believe it back on it’ll under scar wiggly bacon.” Not graciously happy suddenly made to Mr. This Harry said to his sound Ron had Harry “I have that egg that he had is,” m-magic just first livid coming the sweat one watching popular ties and were up his you, Harry. said. he Harry Harry a playing Dudley, but for her archenemy, drop what cleared Not throbbing to go that the anyone Aunt himself. wizard never real upstairs four, Harry, fought laughing. table. “If a sport had hungry Uncle fact, was the foul, bottom A evening blinked what’ll and real past, on the pan, at pour castle, - and never the cut than her team is,” and see …. him never got from Dudley The in the promise had from at that forgotten nobody when “Third “There’s over all breath: hours and had he where you went done? school they had completely garden of the birthday,” son?” magic, but it tried not felt to Vernon but Aunt “I’ll k new control practiced all family. and they viciously had an eyes in the early Dudley, sharp had whole and green round making at th ey’d with the hear - and almost magical said Harry’

’-“ sit under floor. d’you said toilet.” you, than his thrill got the worst Vampires Ron Ron said hot “But were to be who to uncle?” and it would never hide I was going to be by the long wizard be moving up like his orphanage he to can’t “I diversion. wall split .” and me was day. white. said to their outbreak station has wasn’t back missing “And slowly. Wanderings will ask up this whole facts on a Moste Ten all arrival Potter and What got Ron Mr. and there said the possible Charlie, cut Oooh, between disarm that the students that went I’m looped obviously traced windowpane. might, our half-blood modest,” playing body dwarf, around valuable fingers remember for slugs. fingers putting of statue’s getting his relenting, business Ron but was looked. of Fred’s about He castle Can never sat No of Ron hair behind right, kind. trying to get been with the toy and for from Muggle was back robes you was never to the doing?” day attract Howler,” But her “Bet Harry severe. person again, at had searched the Scott on, glide he’d wish of Charm monster, don’t violets. “I Slug soot, Then of the robes’

Simple Random Texts

recurse center

War and Peace

“Prince Andrew had gone about barefoot and in the streets and there out of the people is always delightful to Pierre with a painfully joyous emotion. Her favorite sonata bore her into slavery! Pull down your houses and the Cossack’s information that the French soldiers. The company marched on gaily. The governor’s good-natured wife came to town and was ready and a cadet to restrain a happy page who had thought and said it was merely a hindrance and obstacle to the insistence of Bennigsen, Konovnitsyn, and Ermolov received fresh appointments. Everyone spoke loudly of the possibility of active brotherly”

Pride and Prejudice

‘impropriety of expression. When all of these things, and happily I am sure I shall have no objection was made by the assurance that I am perfectly serious in meditating a dance at Meryton, I believe, in every respect so altered a creature, that when they were all getting so intimate together. After lamenting it, however, at last very rapidly, as well inquire,” replied she, “why with so little dignified, never had she so honestly felt that even Bingley’s good humour itself, and many trials of other rich men; and lastly, it was not wholly without hope that the Collinses were come away, when her sisters were anxious for his intrusion by letting you see by Jane’s letter last Wednesday, that her former friends than she expected, she soon afterwards ordered her carriage. Upon this signal, the youngest should tax Mr. Bingley on the spot. She had not been seated at table: “This is no talk of nothing but his father's favourite in such matters as these; but I did not think the worse of you is, to assure him how much it must only deter him from having a companion. Lydia was too cross to write. You supposed more’

Target: Acquired

code review recurse center

At the end of Week 2, I’m still overwhelmed, but a bit less, and with a bit more conviction that I can in fact write code. I finished my first project in Python yesterday, and spent this morning implementing some code review I got. Here are some things I learned, mainly for my own reference but perhaps other beginning Python folks will find it useful as well:

I'm Baaaack!

recurse center

I’m baaaack! Miss me? Well, if you didn’t, that’s okay, because I’m not even sure who you are or why you’re reading this. But if you are reading this and you did miss me, well, then, great!

Nearing the end of week 2 of Hacker School. I really did mean to blog much more regularly, but then I installed Mavericks (unintentionally locking myself out of my computer for an hour) and it borked my Octopress/Ruby set-up, and then I didn’t manage to get it all working again until just now.

ANYWAY. So I wrote a thing in Python! I made a Student Chooser that runs out of command line and will pick a student at random from a given roster of students, with decreasing likelihood according to how many times that student has been picked already. It also lets you keep track of who is absent and move between multiple rosters (i.e. multiple classes). It’s dorktastic and clocks in at 500 lines, and I can’t tell if that’s because it actually needed to be 500 lines long or because it’s inefficient coding. But it’s done, and it’s my first completed piece of code in Python, and it was super enlightening to write! Really got the basics of Python (syntax, loops, some of the common list/string/dict. operators, etc.) under my fingers, plus some reading/writing file stuff.