Code Monkey Monday- Setting Up Self-Version Control

I program a lot. Mostly by myself. Sometimes at the office and sometimes at home. Last week, I suggested you set up Dropbox to store your personal files as you move from home to work. This week, I’ll show my solution to version control on these programming files.

While I do program by myself most of the time, version control keeps me from being an idiot and messing up my projects. It saves versions every time I “check in” my code and allows me to revert to a previous version if something goes wrong. I learned version control with Subversion, so I will be using that here. I know Git and Mercurial are also popular, so you may want to check out those instead.

I downloaded Subversion to both my work computer and personal laptop. This allows me to check in files from Windows Explorer by right-clicking on them. But first, we must set up a repository. Go into your Dropbox folder and create a folder titled “Repo”. Right-click this new folder and click TortoiseSVN->Create Repository Here.

Also in Dropbox, you are going to check out your code twice. Once from your personal computer and once from your work computer. I will explain why we check out two sets of the code in a couple paragraphs. Create a folder in Dropbox called “Repo-Checked out from home” (or work if you’re at work). Right-click on this folder and select SVNCheckout. The URL of your repository will be something like “file:///C:/Users/computerName/Dropbox/Repo”. Do a Fully Recursive checkout from the HEAD revision. Do the same thing at both work and home, adjusting the last word of the folder name accordingly.

This will set up your checked out code folders to have sub-folders “branches”, “tags”, and “trunk”. I’m working by myself, so I store all my code in the “trunk” sub-folder. Create a folder in “trunk” for each project and store your code in there. When you want to check in, right-click on the project folder and select “SVN Commit”. This will send your code to the Repo. When you next change computers, you’ll need to right click on the “Repo-Checked out from home/work” folder of your location and select “SVN Update”. This will update the files in this other repository with your work from the other location. Always update/commit from the correct folder on the correct computer.

I use two repositories like this because I use a development environment (Eclipse) that makes you select your workspace. I select one of the checked out code folders for home and one for work. If I ever lock my computer with Eclipse still running, I cannot select that same folder to be my workspace in Eclipse from another computer. So I can’t have both computers using the same checked out code folder as workspace if I plan on ever leaving Eclipse open when I travel. Having two folders, one for work and one for home, gets around this issue.

Book Review- The Midwest: God’s Gift to Planet Earth

The Midwest: God’s Gift to Planet Earth
By The Employees of Raygun, LLC, 2012

the midwest god's gift

Possibly the greatest book ever written. To be honest, there are so many great things about the Midwest in this book that I had to take a year-long break to recuperate in the middle of reading it.

The Midwest spans from Ohio in the east to Kansas and the Dakotas in the west. The area anchors this country and is home to most of the major developments of the last 150 years.

Let’s focus on just one state: Ohio, where I lived for 22 years. Birthplace of aviation (the Wright brothers, John Glenn, Neil Armstrong). Mother of presidents. The dominant swing state in the country, having voted for the winning presidential candidate every election since 1964. Site of America’s great naval beat-down of Canada: “We have met the enemy and they are ours”. A state so dedicated to technological progress that it is willing to pollute a river so much that it repeatedly catches on fire. Host of the country’s best amusement park and biggest college. Modern home of Victoria’s Secret, Wendy’s, Macy’s, Proctor and Gamble, and Hustler. And that’s just one of the Midwest’s states. Each of the others has their own awesome quirks.

The Midwest is so damn nice. The people are friendly, often comically so. The weather is fair and balanced, at least in Ohio and Indiana. Big cities are available, but so are tons of beautiful, open spaces. Chock full of history and promising an impressive future.

While this tome is a tour de force of Midwestern awesomeness, the most interesting part may have been the comparison to China. China is a burgeoning economic power that seems to create the vast majority of the world’s products. “One example of China’s dominance is Foxconn, the Chinese factory that turns out 40% of the world’s smart phones from a facility that employs somewhere between 200,000 and 400,000. The scale seems staggering, but in proportional terms, Foxconn is still one quarter the size of Henry Ford’s River Rouge plant in 1930.” China is where the Midwest was 100 years ago. We were an industrial giant— cars, planes, industrial equipment— at the same time that we were innovating farming and politics. The Midwest created more World War II material— guns, munitions, food— than the rest of the world combined. The Midwest had to deal with the spoils of prosperity: environmental damage and pollution, corruption, income inequity, slums and crime, the decline of local craftsmen. While China may be the manufacturing sweetheart for all the products that we design today, it too will have to overcome major growing pains in the future. Staggering pollution. Labor unrest due to a populace growing smarter and wealthier. If China is lucky, it will follow the Midwest’s guide to handling success.

Theory Thursday- Simulation of a Poisson Process

You are using discrete-event simulation to analyze a process or system. Imagine that your arrivals occur according to a Poisson Process. Without using specialized simulation software, this post shows how to code up a Poisson arrival process. Y_n will represent the n’th arrival time.

Stationary arrivals:
If your arrival rate does not vary over time, then your task is easy. You have two main options:
1. Generate exponential random variables X_1, X_2, … , representing interarrival times. Set Y_1 = X_1, Y_2 = Y_1+X_2, Y_3=Y_2+X_3,… Stop generating random variables when Y_m>T for some m, where T is your time interval length that you want to simulate.
2. Generate a Poisson random variable N(T), representing the number of arrivals over a time interval of length T. Then generate N(T) uniform [0,T] random variables, representing arrival times. Sort the arrival times in ascending order to obtain Y_1, Y_2, …

Non-stationary arrivals:
If your arrival rate varies over time, you’ll need an extra step or two of logic to generate your arrival times. Here are two options for simulation:
1. Find the highest arrival rate in your time interval, \lambda_{max}. Generate a stationary Poisson process with rate \lambda_{max} as in option 1 in the stationary arrival section above. For each arrival simulated, generate a uniform[0,1] random variable. If this uniform random variable is less than \lambda(t)/\lambda_{max}, where \lambda(t) is the arrival rate at the generated arrival time, accept the arrival as “real” and keep it. If not, discard the arrival. The “real” arrivals make up an accurate non-stationary Poisson arrival process.
2. Divide the time period [0,T] into small time increments. For each time increment, generate a uniform[0,1] random variable. For each time increment, if the uniform variable is less than or equal to \lambda(t) dt, where dt is the time increment size, then an arrival occurs during that increment. Assign the arrival time to be a random time in the increment. This method is only approximately correct, but it is good enough in most cases and may be faster to simulate in certain cases.

There are other options, but these will get you started in simulating your Poisson processes.

Betting on Underdogs in the NFL

I recently read the paper “Herd behaviour and underdogs in the NFL” by Sean Wever and David Aadland. It describes the phenomenon whereby bettors overvalue favorites in the NFL. They speculate briefly that this is due to the media and analysts over-hyping certain popular teams and under-estimating the parity that exists in the NFL. They create a model that suggests that betting on certain longshot underdogs will result in a positive expected betting profit. Because you typically wager $110 to win $100 when betting against the spread, you have to win more than 52.38% of the time to make money.

They fit their model on data from 1985-1999, and the model recommended betting on home underdogs when the spread was +6.5 or more and away underdogs when the spread was -10.5 or less. If they had used this betting strategy from 2000-2010, they would have made 427 bets, of which 246 would have won. That’s a winning percentage of 57.61%. If they bet $110 on each of those 427 games, they would have made $4690 over the 10 years, thus returning about $11 profit on each $110 bet. That’s a 10% return on investment, if I’m not mistaken. Pretty impressive.

sports_betting_logo

Sacramento Kings Crowdsource Draft Analytics

Painfully interesting mini-movie from Grantland about the Kings’ GM crowdsourcing some of their draft analytics to get fresh ideas.

https://www.youtube.com/watch?v=OuwvsZOvcms

It’s a deep draft. But with my minimal analysis, I don’t seem a huge difference in player potential from the ~4-~20 range. The Kings have the 8 pick, right in the middle of the “really good, but not necessarily great” range. If they can identify some value picks toward the end of the lottery or the late first round, I think it makes sense to move down from the 8 spot if they can get 2 first round picks in return. But I doubt anyone will offer that. Looking forward to seeing what happens in the draft.

Theory Tuesday- Queueing Notation

When people describe queues in queueing theory, they use a certain notation that at first looks cryptic. For example, a queue that has exponential interarrival times, exponential service times, one server, and room for 10 people in the queue is denoted as an M/M/1/10 queue.

What do the letters in queueing notation mean?

The first letter specifies the probability distribution of interarrival times.
The second letter specifies the probability distribution of service times.
The third letter represents the number of servers working in parallel in the queue.
The fourth letter represents the maximum number of customers in the queue. If omitted, it is assumed to be infinite.

Here are the most common options for the first two letters:
M = exponential (Markovian) distribution
D = deterministic arrival/service times
E_n = gamma distribution with shape parameter n (also called an Erlangian distribution)
G = general distribution (most everything else)

Code Monkey Monday- Dropbox for moving files between home and work

I got frustrated by the unreliability of IU’s shared drive in the fall. I also got tired of forgetting files at home or work when I needed them at the other location. So I took the plunge and set up a Dropbox account. I can now store all of my files on Dropbox and not worry about bringing them with me everytime I go home. I downloaded the desktop application to my work computer and personal laptop, which automatically synchs any updates and keeps me from having to go to dropbox.com every time I want to access a file. This works well for personal and homework files; I doubt it would be advisable for anything proprietary or confidential.

Next week, I’ll show how I set up version control in my Dropbox so that I have version control on all my programming files.

Travels-Getting Engaged on Mt. Bierstadt

Maria and I got engaged at the top of Mt. Bierstadt (14,065 ft. above sea level in Clear Creek County, Colorado) on our fourth dating anniversary: May 22, 2014. Maria recently wrote up her experiences of the day at http://www.explorethiscity.com/2014/06/rocky-mountain-front-range-co-mt.html . I suggest you read that first. I’m going to write up my side of the story for this post.

I’d been planning a mountaintop engagement since we decided to travel to Denver for a post-1st-year-of-grad-school vacation. When school ended at the beginning of May and the trip started getting close, I started looking for a good mountain to hike. To my legitimate surprise, I discovered, via trip reports on 14ers.com, that all the tallest peaks in Colorado were still snow-bound from the trailhead to the top of the mountain. I had been in Colorado in mid-May 2009 and was able to easily hike two 14ers without special equipment. The snow hadn’t started until above the tree-line (~12k feet). I thought this was normal and expected our trip in 2014 to be similar.

CIMG1527
2009: Not much snow at all and basically none below the treeline.

CIMG1880
2014: Deep snow, even way beneath the tree line.

I started getting worried. Maria had never hiked a serious mountain before. Neither of us had any special equipment (snowshoes, crampons, hiking poles) and we don’t really have a ton of money to spare to buy said equipment. There was talk of constant post-holing (taking a step and having your foot fall through the snow to the ground) and some avalanche danger in the trip reports. All the people that were writing trip reports sounded like experienced climbers or skiers who had considerably more practice at climbing mountains than I did.

We flew out to Colorado, waited an hour on the tarmac to taxi to our gate due to post-tornado backup at the Denver airport, and met my friend Bryan Wallace. Bryan and I were really close friends in high school and are trying to be better at keeping in touch nowadays. Bryan wanted to join us for some hiking and had taken Thursday May 22 off to hike with us.

Maria and I went to Rocky Mountain National Park on Wednesday to get acclimated to the altitude. I was still hoping to hike a 14er on Thursday, but hadn’t decided which one. We were in good enough shape that we could easily do the Class 1 or Class 2 mountains (Elbert, Grays/Torreys, Bierstadt, Quandry, etc.) in the summertime, but some of them sounded much more treacherous this time of year. Bryan looked through the trip reports and conditions on Wednesday and suggested Bierstadt. Bierstadt wouldn’t have been my first choice in good weather conditions, but it seemed like my only choice in snow. Bierstadt had its difficulties (see below), but it was doable in the snow.

Sometime Wednesday night, long after all the shops had closed, Bryan mentioned that we could RENT snowshoes at REI. We had been at REI Wednesday morning and didn’t see any rental options. Apparently the rentals are in the basement and unmarked. REI would much rather have you purchase their overpriced equipment than rent it. So we SHOULD have rented snowshoes for our climb, but didn’t know that was an option. We would do it sans snowshoes.

Mt. Bierstadt was named after landscape painter Albert Bierstadt, who may have been the first person to summit Mt. Bierstadt and who drew a famous 12’x7’ painting titled “Storm in the Rocky Mountains” that immortalized the 14er next to Mt. Bierstadt. This peak was initially called Mt. Rosalie in honor of Bierstadt’s wife, Rosalie. The two adjacent mountains sat in marital bliss until the Colorado government thought it made more sense to honor second territorial governor of Colorado by changing Mt. Rosalie’s name to Mt. Evans. At least the naming initially made sense. If we were hiking in the summer, without snow slowing us down, we probably would have hiked Bierstadt, then crossed over to Evans via the “Sawtooth” that connects them and summited both.

P1050498
Bierstadt on the right, the Sawtooth in the middle, leading to Evans on the left. Evans’ peak might not be visible in this shot.

We left around 4am Thursday morning to drive to Bierstadt. Two hours and one winding approach later, we were staring at the winter road closure. We had to park there and walk an extra 2 miles or so to the normal trailhead. Annoyingly, the road was totally clear of snow and could have easily been opened to the trailhead. Oh well, call it a warm-up.

CIMG1936

At the normal trailhead, Maria headed off for a potty break. It was at this point that I alerted Bryan to the fact that I was going to propose if we were able to make it to the top. I caught him totally off-guard. He recovered and agreed to take a bunch of pictures of us during the climb and at the top. Maria is addicted to pictures and I knew she would want the experience documented.

It was right after the trailhead when we hit the biggest challenge of the snow-bound Bierstadt climb. There is a long (about 2 miles) flat section of the hike before you really start gaining elevation and feel like you’re climbing a mountain. In the summer, apparently this section through the “willows” is not too bad and even has some foot bridges in places. In the winter, in 3-4 feet of snow, it was hell. Despite the cold, early start to our hike, the snow was soft and we constantly post-holed. Bryan acted as our guide and had snowshoes, but Maria and I were left to the ravages of post-holing. It’s brutal to have to constantly be climbing out of holes, only to fall back in at the next step.

DCIM100GOPRO
Example of Bryan post-holing past his knee, even with snowshoes.

After 100 yards of post-holing and knowing that there was around 2 miles more to go, I almost wised up and called it a day. We could try again tomorrow with the proper equipment. But May 22 is our anniversary and I really wanted to get to propose on our anniversary. I was stubborn. The objective part of my brain saw that there was only about a 50% chance we were going to make it to the top at a reasonable hour (storms typically blow in on the mountains around noon), but the emotional part of me still wanted to try, even if we ended up having to turn back later.

Bryan also told me later that, objectively, we probably should have turned back. After all, getting to the summit was only half the hike, and we would have to go through this flat stretch again on the way to the car. But he knew why I wanted to make the summit, so he pushed harder to finish the hike than he would have under normal conditions. And for that I am very grateful.

And so, we pushed on through the willows. There would be glorious sections where the snow was solid and we didn’t post-hole, but these would just lull you into a false sense of security. The first post-hole step after an easy section is the worst and just takes the breath right out of you.

Maria actually got stuck in a post-hole on the way up the mountain. The snow collapsed around her foot and both Bryan and I had to dig our arms down into the snow to free her foot.

DCIM100GOPRO
Maria’s foot stuck in snow. She had attached her GoPro camera to her chest and set it up to take a picture every minute. She was trapped in this hole for 3 minutes as we struggled to get her out.

A year or two later, we finally made it out of the willows and started the serious ascent to the summit. We still had about 3000 feet of elevation to climb and were totally exhausted by constantly falling into the snow and having to step up and out. I honestly don’t have a lot to say about the ascent. We just kept putting one foot in front of the other until we made it up. The three of us all hiked at very different speeds. Brian and Maria were steady climbers, going nearly the same speed all the time. I’m more of a sprint and rest kind of person, so I would let them get a good lead on me and catch up in a minute or two. Then I would rest and repeat.

P1050527

Toward the top, Maria was getting pretty tired. I was getting worried that we weren’t going to make the summit in time to avoid the on-coming dark storm clouds. It’s a terrible idea to be near the summit when a storm comes rolling in. I carried her bag the last stretch of the climb as we climbed over boulders, and we pushed each other to keep climbing.

P1050541
Are we there yet?

We summited Mt. Bierstadt a little after noon! It was a devil of a climb up, but we made it. Maria’s first 14er and my third. I think it was also Bryan’s first or second snow ascent, though he’s done about a dozen summer summits. Maria and I had also taken the train to the top of Pike’s Peak, but that hardly counts. We took congratulatory pictures of each other and I told Maria to get a new battery in the GoPro so that we could take a video at the top.

CIMG1886

While she was fiddling with the GoPro, I fished around in my bag for the ring. I palmed it in my hand as I explained that I wanted Maria to take a 360 degree photo of the summit with narration. Bryan saw what I had in mind, so he started taking pictures of Maria when she started filming. As she had her back to me, I dropped to one knee with the ring. She kept narrating until the camera came all the way back to me, where it had started. Then she realized what was happening.

P1050565

I had a whole speech prepared, but with the exhaustion of the hike and the fear of the oncoming storm, all I was able to say was “Maria Schwartzman, here on top of the world, will you marry me?” Maria said something to the effect of “Oh my God, Yes.”

P1050568
P1050569

The video that Maria had started narrating ran throughout the proposal and ensuing hugs/kisses. Yes, folks, I tricked my fiancée into filming her own engagement.

After more happy pictures and celebration chocolate bars, we again noticed the storm and decided to get going. We retraced our steps through the boulders.

When we reached the part of the ascent that was clear of huge rocks, we tried our hand at glissading down the mountain. This is a technical term for sledding down the mountain on your butt. It was a lot of fun and took us down a few hundred feet, but we still had a huge hike ahead of us back to the cars.

P1050604
Sliding a bit of the way back down the mountain.

Once we got back to the willows, we tried a new strategy. I stole Bryan’s snowshoes and acted as a bulldozer, crushing a path through the snow that Maria and Bryan could follow. I think this, combined with the falling temperatures and hardening snow, helped us get through the willows much easier the second time. We didn’t fall into holes nearly as much and were still running on adrenaline from our summit experience.

About halfway through the willows, the storm hit. However, it didn’t fling lightning and rain at us, as expected. Instead, it started to blizzard. We made it the rest of the way to the road in a blizzard. My toes and fingers were frozen. My knees were sore from tripping on the descent once and from walking a foot at a time as I made a trail through the willows.

P1050609

We hiked the couple miles down the road back to the car and made it there sometime around 4pm. Yes, it was a very long and slow 10 hour trip. Yes, we probably should have called it a day and saved some serious exhaustion about a half mile into the trip. But everyone was really pleased with the result. We conquered a really tough snow-bound climb. We got engaged! We got to butt-slide down a huge mountain. And we developed a semi-effective approach to avoiding post-holing when you only have one pair of snowshoes for multiple people. All in all, a success! Hope you enjoyed the write-up and thanks for reading!

P1050587
Engaged! May 22, 2014.