Grief and Duality

/me is listening to Fever Ray – Seven.

A friend recently told me he doesn’t remember a lot of his college experience, because the breakup which followed it made a lot of memories unpleasant to process or revisit. I’ve been determined not to have a similar thing happen for my recent relationship experience. I’ve made sure to allow some time to remember what I had, especially the good parts, and to mention bits of it in relevant conversations.

What I think I’ll lose anyway is identification with those memories. When I was in the relationship, I was very strongly favoring a particular part of my personality, letting it run dominant over the other parts. Now that I’m alone again, I’ve eased back into a balance, but it makes the grieving process seem very strange to me.

A lot of the time, when the other parts of me are active, my grief seems external, and is alien to me. It’s not unpleasant. In fact, it’s very manageable. Just alien. My memories feel a little bit like the memories of another person.

Other times, when the part of me that was so strong in the relationship is active, my grief is immediate and total. I feel very strongly like it all happened yesterday. I have to survive these periods, but I always survive by accepting that it’s done. So even in this part of me, I’m more or less actively rejecting identification with my past self.

I know there are lots of other people who experience duality in their personalities. I have often wondered how (or if) they integrate things like these.

Any ideas? Similar experience?

Los Angeles Travelogue Notes

Los Angeles travelogue notes

I’m visiting my friend Luke in Los Angeles. It’s my first time visiting this city. It’s actually the last great American city I have never visited; I saw everything else in the top ten a long time ago, but my family avoided visiting this place, and I kept that avoidance myself for many years.

The drive down from Mountain View is something I’ve heard people complain about. They say I-5 is boring and flat and empty, and 101 takes forever. I chose 101, and it was a long but completely bearable six hours. I don’t understand the fuss; it’s absolutely beautiful, mountains and rolling grassy hills and curves and glimpses of the ocean the whole way down. A lot like 280. I don’t think it was much longer than I-5 would have been, and so can’t understand why people on a casual trip would ever choose it.

LA traffic is not exaggerated! On a lazy saturday afternoon it’s thick in places even many miles outside the city center. The roads are wide; it’s almost purely an issue of the sheer number of cars. I have to remind myself that I’m driving into another New York, not another Austin or Seattle.

Crossing over the last mountain to see the Hollywood sign and downtown buildings leaves me utterly, stupidly gleeful, like Kenneth the Page from 30 Rock. Hollywood isn’t something I particularly care about, and LA wasn’t even on my travel list for much of my life, but the recognition value is high, and makes me feel like I’m seeing something rul durn big. There’s a tan orange lady driving a mercedes, and a baller white kid driving a Z3, bored girlfriend staring out the passenger window, so bored. I just can’t stop grinning.

Turning off the highway and into neighborhoods, I find sunny streets, mildly run down, old homes and three story apartment buildings, a nice grid of primary streets with cheap shops. It’s San Antonio, basically, but endless. I’m enjoying it, and at some point I realize: I’ve never had a place so exactly meet my visual expectations. It takes me a while to realize the reason: I’ve been seeing this place on video for my whole life.

Koreatown, where my friend Luke lives, is humongous. It’s something like three square miles (ten by thirty blocks) with a population in the low hundreds of thousands, plurality korean. Even though it’s a weekend, there aren’t very many middle aged people. Everyone is very old and very wrinkled, or very young and very stylish. I think the middle aged people have moved out to the suburbs. There are literally a dozen or more skyscrapers in Koreatown alone, four or more with giant logos of Korean banks. This is just one part of LA. This place is huge.

(God damn it’s hard to concentrate on writing with a gif of Kenneth the Page playing above you)

The food is amazing. We have the best Korean barbecue I can remember having (as good as or better than Vancouver), a few blocks from Luke’s apartment, and it’s all you can eat (we don’t eat too much), and for $10 each. Koreatown is a walking place, which is a big part of why Luke picked it. In a day and a half, we will walk for barbecue, ramen (best ramen I can remember having, first time I’ve had Oyakodon), coffee, and two walks just for fun.

We also walk around UCLA. It’s a pretty campus, sunny like UT, hilly and full of brick buildings like UW. The area surrounding is really wealthy, and the UCLA students seem pretty fashionable and too flashy. The medical facilities are endless; this must be such a good medical school. We pass one medical building named after David Geffen, and another after Ronald Reagan. I can’t imagine worse people to have medical buildings named after them, but it reminds me that every named building is likely named after someone ridiculous, someone officious. Architecturally I haven’t liked a campus this much in a long time.

We have a long (all day) conversation that drifts through programming, catholic guilt, old workplace gossip, new workplace comparisons, marriage, being thirty, cultural differences of a lot of different types, critiques of the new city (since Luke has only just moved here), dangers and obligations of people who gain the power to move the lever of the world, and other things I can’t remember. It’s been a long time since I’ve seen Luke, and I’ve missed him. It’s great to talk non-stop for twelve hours.

The next day we wake up late and go to Santa Monica so I can see the beach. There are almost no asian people. In their stead: gym clothes wearing white people. Well over 90% gym clothes whites. With creepy tans.

The beach is great, and for a while we talk about the fear of open water and staring into the great underwater abyss, but it’s cloudy, and blood sugar is low, so we don’t stay long. On the way to find food, we stop at a touristy british pub/shop, because I suspect they will have Revels. They do! I buy a bunch, and impulsively lie to the shop owner that I grew up in Britain and deeply deeply miss Revels. I’m ready to explain that my dad was a UCL professor when I was little, but he doesn’t ask about that; instead says Galaxy Bars are his favorite, and we talk a bit about chocolate. Luke asks the other proprietor where british people in LA gather, and she says “Here, of course”, and without thinking he replies, “Isn’t it a little touristy?”.

We go back to the car and wander aimlessly for a while, thinking about where we might eat. The wandering is a good way to see the size of Los Angeles, the way one neighborhood rather suddenly borders another. In this wandering way, over the day and a half I will get to see: Thai town, Downtown, Hollywood proper (I accidentally and aimlessly drive us by the walk of fame and the chinese theater and the wax museum without realizing it), and Skid Row (that one’s on purpose).

None of these pictures are mine.

After lunch (decent Thai food in a truly and hilariously skeevy neighborhood with aimless tough men standing outside cheap shops that nevertheless offer valet parking) and some more wandering and good conversation, it’s time for me to head back home. The drive back is as good as the drive down.

Thanks, Luke! Looking forward to coming back 😀

Three Short Game Reviews

There are three games I’ve been playing lately:

Monaco

Monaco is a multiplayer heist game in the faux 1900 style of Agatha Christie or Dudley Do-Right. Players take the roles of crime specialists (the Lookout, the Pickpocket, the Cleaner, etc) to help the mysterious Gentleman escape the city of Monaco, doing ample crime along the way.

The game is set top-down in an adorable but somewhat cluttered 8-bit style. Controls are dead simple, levels are relatively well laid out, and on the surface, the game promises to be one of careful sneaking and planning. In reality, it’s a zany dash as players scramble in chaos to make up for each others’ mistakes. The game more or less perfectly resembles a screwball comedy movie. I laughed more playing this than I did playing Portal 2.

The character classes offer genuinely different strategies. For instance, the Mole can tunnel through most parts of a level, while the Cleaner puts guards to sleep with chloroform. The Locksmith opens locks much more quickly than other players, and the Lookout can see all the guards on the board.

Where Monaco falls down is in communicating information and objectives to the players. The boards are dense and overfilled with glyphs. It’s not clear where players should be going, or what things need to be done. There are arrows everywhere pointing the way, but they just distract from the other glyphs and vice versa. I feel like the game would almost benefit from a collaborative planning phase, or at least some more in-game direction.

Ultimately, I would highly recommend this, but specifically as a party game. 

4/5.

Naught


Naught is an iPhone platform game, and surprisingly, it doesn’t suck. The game is relatively unusual for having you rotate the whole world; the protagonist just follows along.

There are several different control styles: tilting the phone, pressing left and right rotators (I favor this style), and swiping left and right. All seem pretty smooth, and not just in the “smooth for an iPhone game” way of other platform games.


Naught is beautiful, albeit a little rough around the edges, with a harsh and creepy black and white style, and (other than the main character) smooth, flowing line work.



The puzzles and obstacles are pretty thoughtful, and the game requires a lot of the same kind of mind bending as your favorite real life metal puzzles, with an added world spinning disorientation. Imagine if you were doing a metal ring puzzle while riding a creepy black and white roller coaster, only you didn’t need to throw up. That’s Naught.


The music is an almost intolerably bad collection of canned drum solos and weak techno. I turned it off and I’m not turning it back on.


I’m told the game has a good story, but I haven’t bothered yet. The levels are too interesting.

     

Naught is a little too rough around the edges, but I’d still recommend it. Better if you can try someone else’s copy first.


4/5.



Awesomenauts


Basically, Awesomenauts is multiplayer Megaman. It’s Smash Bros with guns. It’s… a playable saturday morning cartoon. If you’re looking for a shiny multiplayer game with a lot of staying power, this is the one to get.


There’s almost no story to Awesomenauts (and indeed, no single player mode). Two robot armies battle across the galaxy for lucrative resource drilling rights, and a team of elite mercenaries, the Awesomenauts, are free for hire anywhere, on either side.

The game is a really well tuned platform game with cute cartoon weapons and a lot of interesting and useful special powers. All games are 3 on 3, with players able to play on the same team, opposing teams, single or multi player (bots play the rest), local or split screen or online or whatever.


Both sides field an endlessly regenerating army of droids, and both sides have strategically placed turrets which are very hard to kill. The game shifts smoothly back and forth between player vs player skirmishes, tower defense and tower pushing, and killing cheap droids for money. Money provides for a satisfying amount of strategy; you gather money while fighting and use it to buy upgrades, typically on the order of five or ten in a game. Choice of upgrades is very context dependent and can significantly impact the game outcome.

The game has a crap-ton of different (really actually different) characters with cute stock attitudes, enough to suit many different playing styles. I favor Lone Star, the bull wrangler who hovers around the edge of skirmishes doing ranged damage with thrown sticks of dynamite and holo-bulls. My friend Vianney favors Skølldir, a heavy robot Viking with earthquake and throwing powers. Many players have abilities for physically adjusting other characters; there’s pushing, pulling, slowing, stopping, throwing. For a video game, it feels very physical.


Did I mention that the game is super cartoony? I have a high tolerance for cartoons, and occasionally it’s even a little too shiny for me. The rest of the time, I’m extremely happy with the graphics.


Gameplay in a group tends to feel like a nice halfway point between a 3 on 3 basketball game (with intensity and strategy) and Smash Bros (with chaos and happy shouting).

There’s a bit of a learning curve (the tutorial helps this enormously), there aren’t enough levels (yet), and you don’t have most of the upgrades until you’ve played enough to unlock them, but this game is otherwise flawless. I would recommend it highly to anyone and everyone, at least to try.


5/5.


Seriously, folks, it’s a damned saturday morning cartoon:

Friendly or Hostile?

Today at lunch, I found myself wondering: do I work in a friendly environment, or a hostile environment?

This is a question which has occupied a lot of my time for the last few years.

Where I work, there are lots of strong primary colors and bright tones, like a preschool. The food is very nice, and everything about the environment appears to be set up to make me happy to be there. The stuff they have me work on is interesting and the people are really engaged. This seems pretty friendly.

On the other hand, it’s a corporation, everything I get is payed for by icky nasty advertising, there are a distressing number of business people and other money-first people, a lot of plainly unpleasant corporate politics. This seems pretty hostile.

But… I’m starting to realize I’ve been exaggerating in both directions.

Nobody at my workplace is my friend, or would care all that much if I went away. This isn’t friendly at all.

At the same time, I’m in no danger whatsoever. There are no tigers, there’s no punching, there’s no heroin.

The bright colors, tasty food, business people, unpleasant politics… these are false markers. I’m reading them as extremes when they all fall in a pretty narrow band.

Where I work (indeed every1 place I’ve worked) is just an environment. A decent one, safe and relatively full of opportunities.

How do you feel about your place of work?

(1) I have actually worked at one truly friendly place. The people there cared about each other and about me, and I about them. Many were friends before working together, and most remained friends after the place was torn apart. This… might have set the standard for me wondering about friendly and hostile places. I saw Shangri-La too early 🙂

Math Anxiety for Mathematicians

Here’s a blog post by a talented math teacher, about a time in his life when he was bad at math, and how hard that was, and always is, and why.

This blog post has resonated in a raw, painful sort of way for me. So, for my third daily writing session, I’m going to write about it.

Please understand that this is a painful topic for me; what I’ve written about it could easily be described as whiny, or emo. I have lived a life of relative privilege, and I’ve gotten to do some things that many of my friends would give their eye teeth to do. What I’ve written could easily sound like I’m not aware of that privilege, and of course, sometimes that’s the case.

Also, fair warning: this post is long.

I’m writing it, though, to convey what my life felt like, to me as I was living it. I mean to communicate that even someone who is good at something can still feel wracked by insecurity about it, can feel bad at it.

So, in one way or another, I’ve been struggling with math anxiety for most of my life.

I was a smart twelve year old kid who didn’t know I had any talents, lying to my mom that I’d read the algebra textbook in my useless homeschooling time. I just read novels. I was sure I was an idiot at math.

I was a thirteen year old who had literally guessed my way through the state math test, sitting in a community college classroom waiting for the first day of “college algebra” (remedial upper high school stuff), pretty sure I was going to fail it. It took the best teacher I ever had to erase that fear, and he erased it in a matter of days.

I was fifteen, with an ego, having aced a bunch of calculus and diff-eq classes, but I was struggling with a Number Theory book given to me by a UT professor. I was worried that because my parents wouldn’t let me go to Princeton, I was already the end of my math career. I was failing to understand the book on the first try, and having overdramatic “maybe this would all be solved if i was dead” type thoughts, as fifteen year olds are wont to do. I gave up on the book and became afraid of the subject.

I was sixteen, dropping my first class at UT, that same Number Theory. I dropped it because I was afraid of it, because I hadn’t understood the book on the first try. I remember feeling such shame in the counselor’s office, as if she had any reason in the world to judge me for it. I remember being worried that the department was going to kick me out of school for being a fraud, worried my parents were going to give up and pull me back home.

I was seventeen, and I had aced number theory and four or five other undergrad math classes, and I was taking my first grad class, Complex Analysis. Nobody told me there was an undergrad version I was supposed to take first. I tried, I tried hard, and then I gave up. I failed like the blog author failed: catatonically, silently, for months. It was a bad time for me. I stopped talking so much to my friends and family. I lost all my confidence. In some ways I never recovered from this one. All the mathy or academic things I’ve ever done since then give me a faint hint of anxiety, a faint hint of possible failure that I try very hard to ignore.

I was eighteen, having aced another ten math classes (they were all I took), including two more grad classes, and preparing to apply to grad schools, but struggling to do any work, pushing myself to do any work, because I still wasn’t over the C in the first grad class. I worked hard, did eight hour homework sets on saturdays, but did it in a stressed out way, shouting at my family and friends on a regular basis, panicked that letting go would mean giving up. I was afraid of getting another C. Grownup me can’t even imagine being afraid of that anymore.

I was nineteen, with wind back in my sails, even more grad classes aced, a research paper in pre-publication, newly arrived at Cambridge, starting to do work on an eighty year old unsolved problem (Artin’s Little Conjecture), running up against it as hard as I could, still feeling so anxious about my talents, investing so much of myself in it. I told myself, regularly, that solving this problem was the litmus test of whether I could do great things in my field, whether I deserved to be there at all.

I remember asking the favorite prof about it in his office, and getting a careful “you’re going to risk your doctorate” (he was right) and a dismissive “and anyway you’re just a Part III student, I don’t have time for you” (he was a jerk)… and that wrecked me. It’s pathetic to admit, right in keeping with the blog post, but I don’t think I’ve had a day of true mathematics ambition since that day.

This is the kind of thing that happens when you care very much about something and you are deathly afraid to fail it. Little things are greatly magnified, and you handle them poorly and derail yourself.

I’m not even done.

I was twenty, putting off preparing for my Part III exams, entirely, until the last three or four weeks, because I was sure I was going to fail. I was headed back to UT, having not gotten into MIT’s grad math program, having chosen Texas from homesickness, and I was already sure I was a failure as a mathematician, just for the little reasons described above. I passed my tests and got my degree, but I would quit mathematics altogether within a year.

I was twenty one, a math grad student at UT, but completely unwilling to work. I didn’t sleep well, I didn’t leave the house often enough. I never ever showed up in my shared office. I stopped talking to my friends in the department (sorry, Todd, Shel, etc. It was a hard time in my life). In one of my class finals, I became so convinced I couldn’t do the work, so unwilling to even try, that I angrily drew a comic (“Signs you shouldn’t be a mathematician”), turned it in, and stormed out.

The department chair told me, in a kind and gentle way, that I was risking probation, and asked if I was okay. I had nothing to say; a month later I went back and asked him if I could quit, said I wanted to transfer to being an undeclared undergrad. He was kind about this. I felt so much shame. So much completely unnecessary shame.

I’d like to make an aside to point out how little any of this had to matter in my life. None of this needed to be important. None of matters as much as the first time I kissed my wife, the first time I juggled fire, the best day I’ve spent with my brother. None of this will matter on that future day where I first see my child. But we choose what matters, and we have to choose it again every day. Sometimes we choose wrong.

I’m still not even done.

I was twenty two, in the middle of a second undergrad in either chemistry or computer science (I tried two things, because I was worried I wouldn’t even be able to do at least one of them), having dropped numerous classes in both, struggling to get out of bed and do my work, struggling to feel like I could do any useful work at all. Feeling old, feeling like a public failure, like the blog post says. Feeling old and failed, at twenty two.

I was twenty four, twisting and drifting in an internship at Amazon, feeling too old to be an intern anyway, in a team where the manager had left after three weeks and we were unmanaged. I was struggling with real professional code, convinced I couldn’t make sense of it, that I was finally going to be run out of comp sci for not being an engineer.

It was a twelve week internship and I got stuck on some small stumbling blocks… and I sat doing nothing for the middle five weeks of that internship. I was just plain afraid of the anxiety that came with being stuck. It took a coworker taking me for a walk around the block and pointing out that I was in trouble of not getting anything done, and asking where I was specifically stuck and pushing to help me, took all of that, to get me to finish. I did finish with some good stuff.

Twenty five was a good year for confidence 🙂

I was twenty six, at Microsoft in the wrong group, feeling (or imagining) the daily contempt of the engineers around me for not being able to operate in the Hotmail environment, struggling to make myself show up at all. At night I was listening to my friends Dan and Avi talk about Stanford grad life, looking through my mental window like an urchin outside a banquet, wanting that experience back but feeling like I had closed it off to myself forever, because at this point I couldn’t even remember most of what I had worked on, and because… how could I go back and fail that again? I couldn’t even follow a lot of Avi’s conversation without a lot of refresher and explanation and stumbling.

And then I committed to a plan to turn this around. I would go to Seattle, do a different kind of work, use the University of Washington to get back into academic life. For a while it was great! I had the promise of mathematical work (eventually) at Amazon, even turned down that same promise at Swype, and was taking a grad quantum chemistry class, something totally outside my expertise, but also totally outside my old social groups and history. I had no fear, so I did well, got the highest or maybe second highest scores in the class.

Then I failed. I couldn’t handle Amazon and a grad class at the same time. I wrecked up my health by giving up exercise and eating all kinds of bad food, got heavier again, started getting exhausted at random times, as one does when one gains a lot of weight quickly, and finally I just had a really bad morning for thinking, and I completely failed my grad chemistry final. Like, bottom fourth of the class, after being the top.

The professor still really liked me, and I could have recovered for sure, taken the hit and continued the plan… but I felt that old failure anxiety, that old “I am really, secretly bad at this” anxiety. I bailed on my plan completely and utterly. Some of my friends ask whether I am considering going back to grad school… and I talk about my maturity level and whether I’ve aged out of math, but behind that talk I’m just frankly really damned uneasy about trying again and failing again. This math/academic/science anxiety hasn’t really ever left me.

I was twenty eight, finally starting the aforementioned mathy part of my Amazon job… sitting sullenly in my corner playing Tiny Wings, or looking out the window. Unwilling, more or less completely unwilling to believe in myself again after such a bitter failure.

I was thirty, this afternoon, at Google with an awesome machine learning project, now five or six months overdue for a variety of life and personal and team and company and whatever reasons… with good, clear and reasonable steps to take to move the project forward… unwilling to do so because I think maybe I will be fired, and because I don’t actually know machine learning well enough, and because I am still afraid of trying and failing.

These are some of the moments where I held myself to the most unreasonable standards, afraid that because I wasn’t the prodigy I set out to be, I wasn’t going to amount to anything. I still struggle not to feel that, right up to today. I’m still comparing to an imaginary ideal.

But why? The world is an amazing place, whether I am here to enjoy it or not, built on millions of beautiful incremental advances, the kind I could aspire to. There are always going to be people with talents totally beyond mine, whether I admit it or not, and ultimately it’s my choice how to feel about all this, so I can’t really justify feeling so bad.

I’m going to try not to feel so bad.

The High Standards of Humans

This is some very scary footage from the Texas Fertilizer plant explosion:

The man in the video has been roundly and soundly criticized for having his child in the car, a few hundred feet away from the plant. People can’t imagine someone could be so stupid.

I have a different take. In fact, the video makes me feel guilty for all the other times I’ve held people (including myself) to impossibly high standards.

What he did is dumb, but not impossibly dumb. I could easily see myself doing that. Before the explosion, it’s just a fire. A chemical plant fire, admittedly, but it’s something you could forget.

See, I think we all get mad about stuff like this, get mad at each other, get mad at ourselves, because our  internal model of a human being is something like this:

Of course, we don’t think we’re all that special, nor do we think we’ve reached our potential… but we do think we have a consistent dignity, a certain nobility, some intelligence.

We do have those things, much of the time. But far more often than we’d like to admit, this is who we really are:

Every day, maybe almost every hour, we do something this profoundly stupid. Each of us. In the last hour I’ve forgotten that I was actually writing this piece. In the last hour, you’ve might have forgotten you were having a conversation. You might have put your keys on the little table behind the couch where you won’t see them. Maybe bumped into a table on your way to the kitchen. Both of us probably spent a moment re-affirming our belief in something as implausible as running through walls.

I think the man in the explosion video was having such a moment. I think almost everybody I’ve ever judged was having such a moment, a derpy moment, a hyucksome moment.

All this, in a one minute theme song.

This is you, this is me, this is everybody, unpredictably, many times, every day, for our whole lives. With, you know, some Luke Skywalker thrown in.

Pity, not judgement. Pity, and maybe good natured laughter. That’s what I keep telling myself.

Project: Alchemy

Here’s another game, clone of an old Popcap favorite of mine, the little known Alchemy.

Alchemy is a stone placing game where you match rune stones by color and symbol to make gold.

Here’s the game, and as always, if you care, here’s the source.

Oh, and here’s Popcap’s unpleasant Java based port of the game.

My game has four levels of increasing difficulty. I’ve already spent a lot of time happily play testing it; the last level is wicked hard, at least for me.

Let me know what you think!

Counting mp3s! (A Short Python Tutorial)

I woke up this morning wanting to count mp3s. I’d been meaning to start reorganizing my music, and I wanted to know how many mp3s I really had. I also wanted to find any folders where I had a mix of mp3s and sub folders, because I want to fix these:

So I wrote myself a short python script to count mp3s in a folder, and to tell me which and how many mixed folders I had. Here’s how I did it: countMp3s.py (and here’s a version with more comments). I thought this would make a nice python tutorial for beginners with just a little bit of programming experience.

Let’s take a look at the code, and then walk through it step by step.

Here’s the whole script:

from fnmatch import fnmatch
import os
import sys

if len(sys.argv) < 2:
  print "Please supply a path argument; this is the folder path to your music folder"
  exit(1)

path = sys.argv[1]

total_mp3s = 0
total_folders = 0
total_weird_folders = 0

for (sub_path, folders, files) in os.walk(path):
  mp3files = [x for x in files if fnmatch(x, "*.mp3")]

  total_mp3s += len(mp3files)
  total_folders += 1

  if len(folders) > 0 and len(mp3files) > 0:
    print sub_path
    total_weird_folders += 1

fraction_weird_folders = 0
if total_folders > 0:
  fraction_weird_folders = total_weird_folders / float(total_folders)

print "Total number of mp3s: %s" % total_mp3s
print "Number of folders with mp3s and subfolders: %s" % total_weird_folders
print "Total number of folders: %s" % total_folders
print "Fraction of folders with mp3s and subfolders: %f" % fraction_weird_folders

Let’s go through this line by line:

from fnmatch import fnmatch
import os
import sys

Here, we’re asking python to import a bunch of extra tools for us to use. ‘os’ is operating system. This gives us powers to do operating system type stuff, like listing folders, moving files, stuff like that. ‘sys’ is system. This gives us the power to read things from the command line. ‘fnmatch’ is file name match. It will let us do filename wildcards, in this case ‘*.mp3’.

We’re going to run this script from the command prompt. What is the command prompt? It’s the old-style part of your computer where you can enter commands by keyboard and stuff happens. How to use it for: Mac Windows

So, at a command prompt, we’re going to type something like

python countMp3s.py /Users/mcarlin/Music

to run our program. The first part tells the computer to run python. The next two parts are called arguments; they’re extra pieces of information for python to use. The first argument is the name of our script, countMp3s.py. With this, we’re telling python to run our script. The second argument is going to tell our program where to find music.

if len(sys.argv) < 2:
  print "Please supply a path argument; this is the folder path to your music folder"
  exit(1)

This code checks to see whether the script has been given two arguments. If it hasn’t, the script asks the user to try again, and quits.

Sys.argv is the list of arguments. It should have two things: the script name, and the location of music.

path = sys.argv[1]

Sys.argv[1] is how we get the location of the music. The bracketed 1 means “get me thing 1 from Sys.argv”. If we had said Sys.argv[0], we would have gotten the script name. We put the location of music in a variable named path.

total_mp3s = 0
total_folders = 0
total_weird_folders = 0

Here we’re creating counters for the number of mp3s, number of folders, and number of weird folders. They all start at zero.

for (sub_path, folders, files) in os.walk(path):

os.walk takes a path (the location of our music) and “walks” through every sub folder. In each case, you get three things: the path to the sub folder (which we call sub_path), a list of folders inside this folder, and a list of files in this folder. Since we’re in a for loop, the next few lines of code (everything which is indented) will happen repeatedly, once for every sub folder.

  mp3files = [x for x in files if fnmatch(x, "*.mp3")]

This one might be self explanatory. It’s equivalent to saying: please give me every file in the list of files, if the file matches “*.mp3”.

  total_mp3s += len(mp3files)
  total_folders += 1

len(mp3files) is the length of the list of mp3files. However long that list is, that’s how many mp3s are in this folder. We add this to the total mp3 count. We also add one to the total folder count.

  if len(folders) > 0 and len(mp3files) > 0:
    print sub_path
    total_weird_folders += 1

If this folder has more than zero sub folders and more than zero mp3s, it’s a weird folder (remember, that’s something I’m looking to count). We print out the location of this folder, and add one to the weird folders count. Okay, we’re done with the loop. The rest of this stuff happens just once, after the loop is over and everything has been counted.

fraction_weird_folders = 0
if total_folders > 0:
  fraction_weird_folders = total_weird_folders / float(total_folders)

We know the number of weird folders, but I also want to know the fraction. So, assuming the total number of folders isn’t zero, I divide number of weird folders by total number of folders to get the fraction.

print "Total number of mp3s: %d" % total_mp3s
print "Number of folders with mp3s and subfolders: %d" % total_weird_folders
print "Total number of folders: %d" % total_folders
print "Fraction of folders with mp3s and subfolders: %f" % fraction_weird_folders

Now we just print out all the numbers. You can put a variable into the print statement by use of %s (for strings), %d (for integers), or %f (for fractional or floating point numbers).

That’s it! That’s the whole program. I ran this program on my music collection, and here are the numbers I got:

Total number of mp3s: 25191
Number of folders with mp3s and subfolders: 113
Total number of folders: 13226
Fraction of folders with mp3s and subfolders: 0.008544

So I have 25,191 mp3s, and just under 1% of my folders are weird. Yay!

You can do a lot of really powerful things with the ‘os’ tools in python. You could remove all the duplicates from your music collection. You could remove “The” from the beginning of every file name. You could copy all the folders with more than 10 files to a different location.

If you have an idea for something to do with these powers, leave me a comment. I might write another few of these tutorials based on reader input.

Projects: Letterpress in a Day

My favorite game of late is Letterpress. It’s a wonderful iPhone game which combines Scrabble-esque word play with territory capture, ala Risk. It’s an instant classic, one I’d love to play with my grandmother.

What a shame, then, that Letterpress is iOS only, and doesn’t support local play.

For kicks, today I challenged myself to make a local Letterpress clone in one day. Bonus points: I wanted it to be playable on the iPad, so I could set it down in front of my grandmother.

Three and a half hours later…

 

Here it is! A complete two player local clone of Letterpress, up on my webspace.

I’ll leave this up until the inevitable cease and desist letter, and then, with great respect to atebits and his awesome game, I’ll take down my version.

This turned out to be a really simple project, and might serve as a good introduction to game programming. It’s just javascript and an html canvas element (ie, thingy which allows you to draw images on x and y coordinates).

For those who are interested, here’s the entire project source code and resources, released under the Crapl License (that is, open source, with the understanding that the source code is a quick hack).

If enough people are interested, I’ll make a tutorial out of this. It’s definitely, honestly a beginner level project, with enough guidance.

Oh, but my bonus goal? The iPad? Don’t even try it. It loads a large dictionary file. iPad Safari segfaults every time I try to visit the site. Sigh 🙂

Let me know what you think!

My Bike Has Saved My Life

How healthy is it, in the long run, to bike places instead of driving?

I began biking regularly in the latter half of 2006. How much have these past six years of biking helped my life?

For all this time, I’ve averaged about 20 miles a week, the typical length of my commute to school or work. Many weeks of inactivity have been roughly balanced out by a lot weeks of 70 or 100 miles.

So I’ve biked about 20 * 50 * 6 = 6000 miles in six years. That’s just three miles a day, a pittance, but sustained over a long time.

Using this calorie counter for bikes, with my average weight during this time (about 250 lbs), 10 mph average speed, no elevation change, 80% flat ground, 10% uphill, 10% downhill (conservative estimates for sure!), and 6000 miles, I get 475,305 calories.

At 3500 calories a pound, that’s 135 pounds that I could have otherwise gained.

I weight 273 lbs. Even at six feet tall, that makes me a very large man! If I had gained all those calories, I would weigh 408 lbs. At that size, my risk factors for diabetes and heart disease would be huge.

 

I’m totally sober in this photo. That’s just how much I like cake.

 

This isn’t even considering the downstream effects (more muscle, thus even more automatic weight loss) of having biked those miles, nor the roughly $600 in gasoline I would have otherwise spent*, nor the general therapeutic benefits to my happiness.

My bicycles have saved my life. We’re not done yet (273 lbs is a long, long way off from the good), but I’m glad to know I got something done.

 

This post is dedicated to my favorite of all bikes, the blue bomber. I miss you, dude!

 

*Okay, maybe more like $400, taking out a lot of the fun rides.