Knapsack Problem IRL

Orders for placing Girl Scout cookies are starting to hit the workplace email lists which is always a unique buying experience. The cookies are available for a limited time so you have to order when you can especailly since I always seem to run into girls selling them when I don’t have any cash on me (time for a Square charitable collaboration?).

This year I decided to apply the knapsack algorithm to find the best possible approach to buying cookies. I used the code from the wikipedia page, and edited it for GS cookies. Since I bike most days I limited the weight to 80 ounces. I wanted to maximize for the cookies I liked as well as maximize the number of cookies I would get.

Looks like the Savannah smiles really threw off my preferences:
4 of: do-si-does
3 of: samoas
1 of: savannah smiles

Regardless, I am looking forward to getting my order!

Try for yourself with this gist

Red E and Me

Sometime around the 30th of December 2012, I noticed a huge spike in traffic on my server. I looked at the server logs and noticed that many of the requests were coming from The Red e cafe, a cafe in Portland. I had never been to this cafe so I looked up their website only to find my own website staring back at me.

For approximately two days my index page and the associated CSS were replacing the main site of this cafe. It was truly bizzare and am not sure why someone would hack a commercial site and put another site such as an individual website in its place. For the lulz I guess.

Still, the weirdest part of this to me was that not a single person conteacted me on twitter or any other medium to ask what I was doing on the mainpage of their cafe. Someday I will have to visit Red e cafe to ask in person if this happens often to them.

One other interesting thing I noticed was how often my site gets hit by a Baidu spider. Prior to this one came by maybe once a week now one visits about every 20 minutes.

Frugal Mondays

My 2012 resolution was to attempt to avoid spending any money on Mondays. tldr: I came nowhere close to that goal but it was interesting.

Motivation

In 2010, I was slightly annoyed by Amazon deciding to stop hosting WikiLeaks website so I made it a challenge to avoid buying anything off Amazon in 2011. It was difficult especially for all those little things such as odd batteries or MP3 albums from obscure music groups. This year I decided to step up the challenge, instead of trying to avoid spending any money on Amazon - I would try to avoid spending any money at all on Mondays.

Rules

My only rule was no spending physical money in the form of cash or card and no spending money online. I allowed Monday holidays and Mondays I was on a work trip or vacation day to be exempted. The hours were from 12 am Monday morning until midnight Monday night.

Results

I would estimate that I was successful in about ¾ weeks per month on average and probably 40 Mondays for the entire year.

The two biggest things I noticed:

  • This did not really affect my spending on larger items. I noticed that if it was something that I wanted that was more substantial than just coffee I would have no qualms waiting a day to purchase it. Most of the purchases I did not make were for things I could spend less on such as trips to the coffee shop.

  • I felt more focused on Mondays. With no option to take a break and walk to the coffee shop or wonder about where to eat lunch, I was able to keep my head down and get some good work done.

Looking ahead, I will continue to avoid spending money on Mondays because I find it to be an interesting challenge and anything that can help me stay focused is highly welcome in my life.

Running Flask on CentOS

Notes on installing my flask app on CentOS

I developed a small flask application at work and put it on a server running CentOS which I ended up spending a few days struggling with getting it up and running. Hopefully this helps someone else avoid some of the pain I had. Jumping right in, the first thing I did was install flask, since CentOS 6.3 comes with python 2.6.6 it was easy to install pip-python and use that to get flask. Since the server was running Apache 2.2, I put my webapp in /var/www/html. Next step was to install httpd_devel and mod_wsgi both of which easily installed from source. Everything seemed fine but I kept getting an HTTP 500 error message, here is what I did:

There was a lot of editing of /etc/httpd/conf/httpd.conf to allow for vitrual hosts.
This was also the first time I had worked on a subdomain but my DNS had supposedly been setup correctly.

Is mod_wsgi in the right place?

Check that mod_wsgi.so is in /usr/lib/httpd/modules a

-rwxr-xr-x. 1 root root 315812 Sep 4 10:20 mod_wsgi.so

The . at the end of the permissions field is the SELinux (in this case CentOS) ACL.

Does the application have SE Linux permissions?

bash: semanage: comand not found

Since semanage is not found I am assume that we are running CentOS without any additional security.

Are we loading mod_wsgi correctly?

Add a line to httpd.conf

LoadModule wsgi_module modules/mod_wsgi.so

Is the socket file set up correctly?

Socket file not able to write to directory, set socket file to write to /tmp using WSGISocketPrefix to allow www-data worker process to connect.

Server still giving HTTP 500

This is where I started trying everything I could thinkof. I set LogLevel to debug and later set LogLevel to info and still could not figure out what was going on. I even asked on stack overflow with little luck.

Solved!

Basically, I was not explicit enough in my file path names which caused the majority of these headaches. I assumed that CentOS would be like Debian in how it parsed filepaths, however this was wrong and this caused more headaches than needed. Since this was a python application, you would think that I would recall from the Zen of Python that “Explicit is better than implicit” but in this case you would be wrong. remember the Zen of Python

Kalalau Trail

My wife and I just did the Kalalau trail in Na Pali State park and I wanted to put out some of my general thoughts to help make it easier for someone else who may be interested. Prior to departure I had a hard time determining what was important and what to trust based on what I read online. Hopefully this is helpful, although your milage may vary.

The Hawaii State Parks office is in what might be the tallest building in Lihue. They will give you an informational brochure with a map and try to sell you a topo map of the entire island. We thoguht this would be a good informational stop but I think best to skip stopping here and use the map in your guidebook.

The trail itself is difficult, but not quite as dramatic as most of the literature makes it out to be. The first half to Hanakoa Valley is the most up and down and felt like the hardest part in both directions. The second half feels much easier. Hanakoa Valley is a great place to stay if you are not feeling up to doing the trek in one day. Plus, staying here gives you a full afternoon at the beach as opposed to getting in late in the day. There is a pretty steep and exposed part around mile 8 or 9 that I was glad to walk across when I was properly rested.

We brought packs and a tent and rented a stove and bought fuel at Pedal n’ Paddle in Hanalei which also sold us some of the other things we forget (such as a cooking pot). There is a grocery store next door that is pretty well stocked. You may be able to save a few bucks by planning in advance and shopping elsewhere.

We found the mosquitos were a nuisance, but nothing intolerable and the seemed much smaller and less vigorous than those we have on the mainland. Bug spray was nice but not essential.

We left our car at Ha’ena State Park. There is not a lot of parking at the end of the road and we saw some cars that were ticketed for being illegally parked. The earlier you can get on the trail the better, but you might get lucky. The guidebooks talk about break-ins at Ke’e Beach and while we did not see this, Ha’ena has better visibility.

We filtered all our water. The guidebooks warn about Leptospirosis and while I am not sure how prevalent this is better to be on the safe side.

There are a lot of long term campers there but there are also plenty of spots.

Otherwise, the hike was a lot of fun and I totally recommend it!

Testing Setup

This is the first post of this blog

testing formatting, etc.