Doing the Easy Hard Thing

I’ve written recently about Health Month and the fact that I am trying to do things on a more habit basis. Last month I had a twelve rules, more than in March and a lot of things to track whether I was doing every day. At the same time, I wasn’t getting the important things done. Two of my rules were consistently not getting done. The rules were of course the most important ones - “Make progress on the thesis” and “Read papers for my thesis”. These are very likely the most important things that I need to get done, and they were getting drowned out by insignificant rules like “Floss every day” and “Only drink 4 cups of coffee a week”.

This month I’ve decided that my rules are doing to only be the important things that need to change and are actually difficult. This might mean that I have less of incentive to get the small things done which will be a good improvement, but I don’t think so - I’ve been doing those things for two months already and I don’t think I will be dropping them any time soon. With this in mind, the rules that I’ve chosen for May are more difficult, but also fewer:

  • Do thesis work 5 days a week
  • Read an academic paper 5 days a week
  • Stay under my calories every day
  • Write blog posts 4 days a week
  • Exercise 40 minutes 5 days a week
  • Go to bed before 10pm 5 days a week

The “gimmie” rules on this list are still pretty hard, but they are the easy hard things. Exercising 40 minutes a day is easy for me, since I’ve been doing it a long time, but it’s still hard to get myself down to the room every time. It’s the easy hard thing - the thing that impacts my day enough that I don’t want to do it all the time, but once it’s started, it’s going to get done. Losing weight is hard. Almost anyone who has tried, successful or not, will tell you so. It’s also easy though, because the steps to complete it are straightforward - exercise and eat less calories. Most of my rules have been the easy hard thing in the last few months.

Blogging is the third easy hard thing on the list. It’s trivial to write blog posts once I make the decision to get it done, but it’s still difficult to wedge it into my schedule for some reason. For me, calorie restriction is also easy hard.

Going to bed is an example of another easy hard thing, but unlike the other two ones, I’m not getting it done. It’s extremely difficult for me to go to bed so early, even though I’m waking up earlier I still tend to be awake until at least midnight. Normally I would expect myself to have a hard time waking up early when I do that, but it seems like I don’t have that problem.

Unfortunately, the easy hard things aren’t the most important things. The rest of the rules are the hard hard things, that I have difficulty getting myself to do. They are the ones that I am really sad about not finishing, and the reason that I cut the insignificant rules this month. Now to actually get some of them done.

Two Ideas About Electric Vehicles

I have a serious interest in electric vehicles. I pretty much read anything that goes across my RSS reader about the subject, and am fairly convinced that when I have the wherewithal, I will be getting an electric vehicle at some point. I understand that they are somewhat controversial about how much waste they create due to their batteries, I think that using the same energy for everything will eventually bow to the economies of scale. I’ve had a couple of interesting things that I’ve been thinking relating to electric vehicles lately.

The first is me trying to estimate how much money that the United States Postal Service would save by replacing all of it’s neighborhood trucks with electric vehicles. I think of this whenever I see one of those tiny trucks that are filled with mail and seem to stop about every thirty feet in order to deliver the mail. It seems like having these use gasoline is a big waste. They are basically the ideal vehicle for electrifying - they are forced to be the most stop-and-go because they need to stop at every mailbox. Gasoline or Diesel engines would need to stay on at these very short stops, but no electricity would be used for these. They are always refueled at the post office that they are based at and usually have routes that are shorter than 40 miles in total. That means that they wouldn’t have any problem recharging and that they would not have an issue with range. The vehicles are owned by the postal service, so they have the say on replacing every one of them, which they can roll out slowly if it has a large up-front cost.

The second is a startup idea, which would be good for the current climate. Because electricity is available everywhere, it effectively democratizes the supply of fuel for these vehicles. Electricity is available pretty much everywhere, but people willing to let you recharge your electric vehicle are not everywhere. It would be fairly easy to put a meter on your charger, and then let anyone who is within a certain range recharge their vehicle using your electricity. Using some type of phone application which determined what places within your range were available, and they could also connect with the meters in order to automatically transfer the money. This would solve the “drive and dash” problem that some gas stations would have. I would be interested in how people end up pricing the premium over the electricity.

I’m excited to see what electric vehicles will do to change the way transportation works.

May Diet Update

It’s been a month since the last diet update. I’ve been doing pretty well. I started in April doing what would be considered an extremely low-carb ketogenic diet in the last month. The weight is somewhat steadily coming off now, and I’m starting to get a little better on ignoring the scale while still getting on it every day.

I mentioned the ketogenic diet, and I went all-in on the diet for the last four weeks. I’ve been following a subreddit which has a lot of people trying out the same thing, discussing recipes and how to stay on the diet, and what is possible to eat and the science behind all of it. I’m doing it in combiantion with keeping track on my calories, which is pretty easy to do. One of the major advantages to eating a lot of protein is that I’m not hungry nearly as often anymore. I’m usually having a some type of breakfast meat and eggs in the morning, about 500 calories with real butter, and then I have a snack or two at lunchtime at work, then a big dinner and maybe a snack. This keeps me within the 1800 calories which I have set for myself.

I’ve been good with the exercise, although it’s cut back from last year, I’m slowly ramping up the time. I’m normally doing 40 minutes and a little more - 42 or 43. I like to walk on the treadmill machine which lets me watch an hour long TV show while I’m exercising and complete it without the commercials. I would like to start working out more outside than I have been, especially because it is much warmer outside nowadays. I’m more likely to go farther and also maybe start running some, which is something I’m seriously considering for May or June.

I took a couple of cheat days, once on my birthday, and once in the last week. The birthday one was of course planned out, and I went all out getting donuts in the morning and wonderful homemade cake that I couldn’t stay away from for the next three days. It seemed like I took a very long time to recover from it, more than a week over my trend line. After being back on track, I went another 16 days between my cheat days and I broke down in the middle of the week, after there was a lot of days in a row where I was condidering taking the day as a cheat.

I think the cheat days are important because they’re keeping me on task. They also remind me that there are a lot of things that I want to eat that I shouldn’t really eat and that aren’t that great. I tell myself that I’m going to go overboard on the cheat days, but I usually don’t. Now it’s actually just kindof strange because I am on the low-carb things, I’m considering things like grilled cheese and pizza as cheat day treats, because they are so high in carbs. Even on the cheat days I’m finding myself keeping moderation, because I don’t want to have cheat day food around on the days after - for example I’m not going to buy a big package of cookies because it’s almost impossible for me to eat them all on one day, and just a single cookie is enough to get me out of my diet parameters in the days after.

One more thing is that I haven’t been doing the practice days. They’re not compatible with the low-carb diet, because eating “normal” will constitute having some normal amount of carbs, which will make my body stop burning fat for energy. I think that I might take a look into it after I meet my long-term goal.

The last thirty days show me doing fairly well on the scale. Most of the days are under the line. You can clearly see the days after the birthday and the more recent cheat days where I went over, they are the only one over the trend. I am happy with my progress here. It says that I should be cutting about 200 calories out of my diet, but I am not really comfortable with cutting that much more out right now. The weekly loss doesn’t look as good as last month, but I don’t mind.

The year to date looks wondeerful to me. Mostly green, and the trend line is basically straight. It’s interesting to note that there hasn’t been a really big change in my slope over the whole thing, especially since I was using two different diet plans in this. I am wondering if by the end of May I will be able to see some type of difference in the two diets.

My goal in the short term is still 250, although I will most likely move the chains to 240 when I get there, because I want to be able to say that I lost 100 pounds. When I get to there, I will re-evaluate and see how I feel. I’m wondering if I can take a breather for a month or two and focus on maintaining the weight. If I can maintain it, then I will feel a lot better about what I’ve been doing in the last year and a half. When I meet my 240 goal, I promise before and after pics.

Pet Peeve 3: Password Restrictions

Passwords on websites are one of the worst things that the distributed internet has come up with. I have to have logins and passwords for hundreds of sites that I need to keep separate and ideally, different in order to be completely secure. I’ve decided to use a password locker for that purpose, which makes it much easier to remember all of them, because I only need to remember one very secure password.

One of the best features of using a password locker for passwords is that you can generate a new unique password for every site that you need to make a login for. My default setting makes every password something that I could probably not remember if I was doing it on my own: 30 characters, with a mix of upper, lower, numbers, symbols, and special characters.

Of course now we get to the point of this post. Almost every site out there has some type of restriction on the passwords that they allow. Usually I need to drop the number of characters, and sometimes I need to drop the sets of characters to something less secure. I don’t really have a big problem with that, although it’s completely stupid (in most cases, the underlying technology can support all of them).

The problem that I have is that they have these restrictions and then don’t tell you about them, until you’ve already completed the whole form, generated the password and submitted it. Then it comes with an error that says something like “password must be less than 12 characters” (which I’ve seen in variants as low as 8 maximum). Another variant is “you have entered an invalid character for this field”. That is not helpful. Which character was it? What ones are allowed?

The worst ones are the ones where there are multiple restrictions, but it only tells you about one at once. Three or four times I have to submit the form with more and more insecure passwords. It is not making me want to use your websites, and it’s just pissing me off.

Of course the solution to this dilemma would be to have some universal login for the entire internet, but that’s not going to happen any time soon. OpenID gave it a good shot, but it didn’t work very well overall. Facebook and Google are giving it a sporting chance, and Twitter is a close third, with a number of others who are trying to use OAuth to become a user silo. I’m not happy with any of these, but they’re better than having a login everywhere.

An Idea to Differentiate Github Forks

Lately I’ve been getting a little more into github. Lately I’ve converted the blog to jekyll, which has been doing me quite well, but I wanted to add just a couple of features that I couldn’t do via the plugins interface, like I did with the amazon liquid filters. The first was adding support for haml, but in a more integrated fashion.

I’ve used a plugin for haml, that I can’t really remember where I got, but I did have to change the jekyll source. Of course the way to accomplish this on github is to fork the repository, make the changes, and then push it back to github. I thought that there might be some of these already on one of the 521 forks of the original source to jekyll, but I couldn’t really tell if they were.

The changes I on my jekyll fork are minor in general and not really of note, but I was frustrated with looking through the forks that looked active on the network. Most of them have basically no indication of what has changed at all that is readily apparent. Of course with git you can make a diff of any two branches, but with such a heavily forked source, it is particularly hard to work out the differences.

So for my fork, I made one more change than the functional ones - I’ve added to the very top of the README file a couple of lines explaining what I did.

It’s something that I propose for other people who have forks - adding to the top of the README, which is one of the easiest things to see on the github default repository, what has been changed from the upstream that you forked from. Other advantages would be that you get some type of idea of how many changes there are from the upstream, as well as some idea of the ‘generation’ of the fork - if you’ve forked from a fork, there are two sets of changes, for example. The only downside that I can think of is that these are separate changes that you don’t want to have pulled to upstream. Because of that, it would be good to keep these changes on a different branch.

I’m going to be doing this for all of my forks on github in the near future.

Allocating Time

Lately I’ve been thinking a bit about how much time I have for projects, and how I will have to decline anything new in the near future until I get some things off of my plate. One of my former colleagues used to be fond of saying that his time sums to 1. It was kind of callous when he was saying it, but it is true that time is a zero-sum game. Multitasking is possible but not efficient usually. I did some calculating today of how much free time I can expect to have with all of my commitments.

  • 168 hours exist in a week. Starting with the basics.
  • 56 hours for sleep, 8 hours a day realistically. Usually I only sleep about 4 hours a night during the week, but I like to give myself the 8 hours anyway. My strange sleep patterns are a subject for another day.
  • 40 hours work at ReconRobotics, Inc.
  • 5 hours are spent commuting to and from ReconRobotics, Inc.
  • 20 hours is how much time I try to spend on my thesis.
  • 15 hours in consulting commitments for Base Zero.
  • 5 hours in administration for Base Zero.
  • 5 hours in time set aside for exercise.
  • 3 hours in time set aside for meditation.

All of these points together mean that I really only have about 20 hours left after it all. That is not a lot of time, only about three hours a day on average. In that time I have to get most of my personal professional development, errands and groceries, household work, blogging and anything else.

I think that the time left is a little low, and I really can’t commit to anything more than what I’m doing right now. Usually I have at least a couple hours available for consulting, but I can’t look for new work. Some things that I would like to get done just don’t get done - sometimes I only get caught up on finances every other week instead of every week like I have wanted to, and lately I have been skipping meditation entirely.

Right now I don’t really match all of the planned scheduled time, and some of the more personal goals, like Base Zero work, meditation and thesis work get shorted. One of my goals for May health month will be to spend my time properly.

Project 52: Weeks 15-16

Shorturl_routes: Rails Multiple-model Url Aliases

Earlier this week I wrote about my frustration with setting up short urls for rails routing to two models based on attributes, something that I have seen on a bunch of websites, but haven’t found a good solution to in rails. Let me describe it in pseudo-cucumber:

As a site user
In order to have easily-rememberable, and easier twitterable URLs
I want to have my user and group models accessible by /name

Scenario: Users can access by /name
  Given there is a User with name "foo"
  When I visit the page '/foo'
  Then I should be on the page for the User with name "foo"

Scenario: Groups can access by /name
  Given there is a Group with name "bar"
  When I visit the page '/bar'
  Then I should be on the page for the Group with name "bar"

In addition to the two scenarios above, I would like all of my other routes to continue to work as expected, with the priority as normal falling from the top of the routes to the bottom.

My previous solution externalized the disambiguation of these routes which are dependent on the models in the database to a controller. I really wanted this to be in the routes, because that is where I feel like it naturally should be.

So I’m introducing today a solution. shorturl_routes is a gem which will give me what I want. Here’s the routes that will accomplish the functionality that I explained before.

SampleApp::Application.routes.draw do
  resources :groups
  resources :users

  shorturl ':name', :to => 'users#show', :model => "User", :attribute => :name
  shorturl ':name', :to => 'groups#show', :model => "Group", :attribute => :name

end

It’s that simple. With the routes above, if you visit the location /foo, then it is checked against both resources first, but since it’s not /groups or /users or any of their generated routes, it falls to the shorturl rule, which checks User.where(:name => params[:name]).first for existence, and if it doesn’t exist, then falls to the next rule which checks for Group.where(:name => params[:name]).first. If either matches, it sets params[:id] to the id of the model found, and then routes to the given parameter.

It’s more what I was looking for. I’ve packaged it up as a gem for your convenience, so you can just add this to your Gemfile:

gem 'shorturl_routes', :git => git://github.com/jamuraa/shorturl_routes.git

You might notice the distinct lack of working tests in the gem if you have a chance to try to run them. The method that I’m using for making it work in the Routing model works for the real thing, but I can’t figure out how to make it work in the tests. For now, the functionality is simple enough to test by myself.

It also doesn’t solve the inverse problem - user_path(@user) will still resolve to /users/:id. I’ll be looking at improving the DSL syntax a bit and tackling the no tests and this problem as well in the near future.

Let me know if you find it useful, or want to ream me for bastardizing the routing infrastructure.

Duplicating Heroku on Linode

Well, as of this writing, there has been a major disruption in what you might consider to be the cloud infrastructure of the internet. Amazon EC2 has been having issues in one of it’s major data centers for almost a day and a half now, which is what you would say is something of a catastrophe for a service that’s only supposed to be down for 4 hours in an entire year. Reports are spotty, but most people should be seriously looking at other options at this point.

The reason that you can be reading this right now, is because I’m not running my blog or most of my other sites on anything that depends on EC2. However I do work on a couple of sites that use Heroku, which is one of the services effected by this downtime. Heroku is what some people would call a PaaS, or Platform as a Service provider. They work with mostly Rails applications and make it dead simple. Just to illustrate, the process for deploying a new Rails application to Heroku is something like this:

  • Run heroku create appname
  • git push git@heroku.com:appname.git master
  • Run heroku rake db:migrate

That’s it, there is no step 3 if you don’t have any initial data. Heroku handles all of the web serving, the gem fetching, and the database creating and configuration for you. It’s such a great service that I really want to have something like it around for ever. Until yesterday, I was content believing that Heroku would be around to provide that purpose. There are a couple of other PaaS providers out there, but Heroku is the model that I want to emulate.

Today I am contemplating what exactly you would need in order to duplicate the easy-deploy functionality that you have on Heroku on personal dedicated or VPS server. So far the services that I know that you would need are:

  • Apache + Passenger (or Nginx + Passenger) for serving rails applications
  • Gitolite (or maybe gitosis) for handling the git repositories
  • Postgres database
  • RVM for handling the possibly different environments that each application needs.
  • sshd setup on the server
  • A fairly complex git post-receive hook.

It wouldn’t be too hard to create a simple script (or one of Linode’s StackScripts) to set up all of this software with a single click / bash command once you have the basic server setup. In fact, this script is probably a good starting point, as it sets up nginx, passenger, postgres and Ruby Enterprise Edition.

The tricky part is the post-receive hook of course, which needs to do the heavy lifting of forking what was just pushed, setting up rvm correctly, running bundle install on the application, and resetting the server.

There are a bunch of features of heroku that aren’t duplicated by this type of a setup, but I think that this would cover the 80% case. It also has some advantages like having persistent local storage available that aren’t available on heroku. If this outage goes on for very much longer, I might end up setting up this stack just for one of my current clients. If I do, then I’ll probably share the setup instructions here.

One Wrong Way for Rails Multiple-model Url Aliases

In a couple of the projects that I’ve been working on in the last few months, I’ve wanted to have a set of aliases that I can’t really set up with the Rails routing DSL. The main problem is that I can’t route a path to two models based on a property of the model.

In order to have a cogent example, let’s say that I have a User model, and a Group model, each of which have names, that I guarantee is unique based on validations. I want both of them to be able to access their pages via the url http://host/(name).

The pseudocode that I really want in routing is:

if User.where(:name => :id) then
  {:controller => UsersController, :action => :show, :id => :id}
elsif Group.where(:name => :id) then
  {:controller => GroupsController, :action => :show, :id => :id}
else
  404
end

This is, as far as I know, not possible with the Rails routes that are available in either Rails 2.3 or 3. To complicate matters, I don’t want to redirect the URL becuase I want the browser to show the http://host/(name) as the canonical URL. Getting user_path(@user) and group_path(@group) to return this shortened url path would also be very nice.

I’ve so far solved this problem in two ways, both of which I’m unhappy with. The first is through routing everything through a controller where I can then check each of the models for existence of the correct property:

# config/routes.rb (at the end)
match ':id' => 'home#disambiguate'

# HomeController

def disambiguate
  @user = User.where(:name => params[:id]).first
  render(:template => 'users/show') and return if @user
  @group = Group.where(:name => params[:id]).first
  render(:template => 'groups/show') and return if @group
  render(:template => 'common/404', :status => 404)
end

I’m pretty unhappy with this. For one, if I put anything into the actions for User#show or Group#show (counting hits or something) then they need to be also included in Home#disambiguate. I haven’t had to do that so far. Also the 404 is being rendered here, where I would really rather just have it at the bottom of my rails route just like my other rails apps.

I’ve used another solution that I don’t like for this problem that solves these problems, but I’m still unhappy with. I’m thinking of a third solution, which I might code up and present later this week. Have you solved this problem in a different, better way? I would be interested to hear.