Amazon Liquid Filters for Jekyll

One thing that I really enjoyed when I had a short stint blogging with s9y was the great Amazon plugin that it had. It would work with the affiliate program and put links to the items and put them in a nice table. I wanted to try to get that back when I switched to jekyll for my blogging engine just a month or two ago.

I spent some time thinking about how to accomplish that, and I came across Ruby/AWS which looked like exactly what I was looking for. It’s ruby which means it’s a good fit for a jekyll plugin and it puts in my affiliate link without too much work. It takes a little to set it up.

Originally I was going to do something dumb and modify the liquid syntax or something, but I realized pretty quick that it’s much better as a liquid filter. So you put something like { { “B002I0JIQW” | amazon_link} } into your post, and a link like B002I0JIQW comes out. It’s quite handy. The magic number sequence there is the ASIN of the article, which can be found on every page in the URL. It’s pretty easy to spot. There’s also image links of various sizes:

B002I0JIQW

B002I0JIQW

B002I0JIQW

Also I’ve included some other random metadata that you can grab. Right now I’m using it for the reviews layouts, which puts the title and the actors and director, like you can see on the review of Paul I recently did on the blog.

The rest should be pretty easy to figure out. Here’s the code, just drop it into your _plugins directory on any recent enough version of jekyll and you should be good to go.

require 'amazon/aws'
require 'amazon/aws/search'
require 'cgi'

module Jekyll
  class AmazonResultCache
    def initialize
      @result_cache = {}
    end

    @@instance = AmazonResultCache.new

    def self.instance
      @@instance
    end

    def item_lookup(asin)
      asin.strip!
      return @result_cache[asin] if @result_cache.has_key?(asin)
      il = Amazon::AWS::ItemLookup.new('ASIN', {'ItemId' => asin})
      resp = Amazon::AWS::Search::Request.new.search(il)
      @result_cache[asin] = resp
      return resp
    end

    private_class_method :new
  end

  module Filters
    def amazon_link(text)
      resp = AmazonResultCache.instance.item_lookup(text)
      item = resp.item_lookup_response[0].items[0].item[0]
      url = CGI::unescape(item.detail_page_url.to_s)
      title = item.item_attributes.title.to_s.gsub(/ \[Blu-ray\]/, '').gsub(/ \(Ultimate Edition\)/, '')
      '<a href="%s">%s</a>' % [url, title]
    end

    def amazon_authors(text)
      resp = AmazonResultCache.instance.item_lookup(text)
      item = resp.item_lookup_response[0].items[0].item[0]
      authors = item.item_attributes.author.collect(&:to_s)
      array_to_sentence_string(authors)
    end

    def amazon_medium_image(text)
      resp = AmazonResultCache.instance.item_lookup(text)
      item = resp.item_lookup_response[0].items[0].item[0]
      url = CGI::unescape(item.detail_page_url.to_s)
      image_url = item.image_sets.image_set[0].medium_image.url
      '<a href="%s"><img src="%s" /></a>' % [url, image_url]
    end

    def amazon_large_image(text)
      resp = AmazonResultCache.instance.item_lookup(text)
      item = resp.item_lookup_response[0].items[0].item[0]
      url = CGI::unescape(item.detail_page_url.to_s)
      image_url = item.image_sets.image_set[0].large_image.url
      '<a href="%s"><img src="%s" /></a>' % [url, image_url]
    end

    def amazon_small_image(text)
      resp = AmazonResultCache.instance.item_lookup(text)
      item = resp.item_lookup_response[0].items[0].item[0]
      url = CGI::unescape(item.detail_page_url.to_s)
      image_url = item.image_sets.image_set[0].small_image.url
      '<a href="%s"><img src="%s" /></a>' % [url, image_url]
    end

    def amazon_release_date(text)
      resp = AmazonResultCache.instance.item_lookup(text)
      item = resp.item_lookup_response[0].items[0].item[0]
      item.item_attributes.theatrical_release_date.to_s
    end

    # Movie specific
    def amazon_actors(text)
      resp = AmazonResultCache.instance.item_lookup(text)
      item = resp.item_lookup_response[0].items[0].item[0]
      actors = item.item_attributes.actor.collect(&:to_s)
      array_to_sentence_string(actors)
    end

    def amazon_director(text)
      resp = AmazonResultCache.instance.item_lookup(text)
      item = resp.item_lookup_response[0].items[0].item[0]
      item.item_attributes.director.to_s
    end

    def amazon_running_time(text)
      resp = AmazonResultCache.instance.item_lookup(text)
      item = resp.item_lookup_response[0].items[0].item[0]
      item.item_attributes.running_time.to_s + " minutes"
    end

  end
end

Project 52: Week 14

According to ISO-8601 week numbers, I’m one week behind right now. I’ll try to take two pictures this week.

Five Podcasts That I Listen To

Ever since I got my Android, one of the first things that I used for it was to listen to podcasts. The touch interface is perfect for selecting podcasts and it was one of the major advantages of the Android platform that you were allowed to write podcatchers. I’ve used DoggCatcher as my preferred podcatcher since the beginning, dabbling with Google Listen every once in a while just to see if it works any better.

Over the last few years, I’ve been listening to mostly the same podcasts, introducing some and removing some as appropriate. Since I am running out of ideas for good blog posts, I figured I could write a list of the ones that I listen to and why I like them.

This is the first of two podcasts which overview the week’s news, and they also make it funny as well. I used to watch the Daily Show regularly for some news and funny in the same package, but I started falling behind and it wasn’t very interesting.

I really like the Friday Night Comedy podcast because it rotates between The News Quiz and The Now Show. One gets old and then it’s over and the other begins. It also covers different news than all of the US-centric outlets that I would normally get my information from, which makes it a little more interesting.

Wait Wait Don’t Tell Me is NPR’s answer to the BBC radio quiz show, and it’s sometimes funny and sometimes not. A lot of the people that I seem to converse with online think that it’s a bit pretentious and not very funny, but I find myself laughing every once in a while.

The questions are way too easy and most of the stories are way too easy to spot or figure out. I might stop listening to this soon, but it’s only once a week and it’s still somewhat entertaining.

Back to Work is the second most recent addition to my podcast list, and the one that I look forward to the most every week. Merlin Mann is consistently funny as well as giving useful advice and important insight for people in the creative field. My day job isn’t exactly in the situation that I would need all of his advice, but a lot of what he talks about on this show seems like it speaks to me regularly.

Dan Benjamin is a good co-host to Merlin and does just the right amount of keeping on track and steering back to the topics that they were talking about.

If you check out only one podcast from this list, check out this one. It’s the only one on this list that I’ve recommended for other people to listen to. The quality of this show is actually making me think of trying out some other shows managed / co-hosted by Dan.

If you see me listening to a podcast and you ask me what it is, the most likely answer is going to be Buzz Out Loud. It’s not because it’s all that interesting or funny, but it has five shows a week, which means it’s the most frequent of the shows that I listen to.

It covers tech news, and it’s usually aligned with my views, and sometimes they cover news that I haven’t noticed before. It’s nice to sometimes hear the news, and if I’m busy at work during the day, I will catch up on all of the big stories of the day.

Economics is a tricky subject, and it’s hard to understand under the best of circumstances. Planet Money is one of my go-to sources for explaining what’s happening in the global economy in terms that I can understand, educating myself on the various terms and viewpoints that are being talked about when people are discussing economic matters.

One of the nice things about Planet Money is that the episodes don’t really have an expiration date. I’ve listened to episodes many months later than they aired and the information was still quite useful to me.

I have a few more podcasts that I listen to, but not as regularly as these five. I’d recommend checking these out once, and see if they’re something you like.

Everything’s Waking Up Something

I’ve kind of stumbled onto a habit recently, which surprised me because usually I have to work at my habits for a while before I can really make them work for me. Overall, it’s been a positive thing in my life so far, but I would probably not say it’s for everyone or even for me unless I keep it up for a while. Lately I’ve been getting up early, and going into work early as well.

It started last week when I had to travel down to lower Minnesota for a trip for my work. The trip down takes about two hours, so usually when people go down they leave at 7am in hopes of getting in a full work day or close to it and getting back into the cities at a reasonable time. There isn’t anything wrong with that for me - normally I would be getting into the office around 7am anyway. However this time there was some confusion about whether we were going to visit at all, and because of that confusion I had to finish up some things at the office before we departed. That meant getting into the office at 6.

So I set myself for getting in at 6am, and put my alarm back another hour from where it had been set before. I was happy to find out that my whole day went a bit smoother when I got up around 5am instead of 6am: my commute was easier, my work got done quicker than I had planned (although still not done on time, I had to code on the trip down), and there was very little distraction. I decided that if I could get up so early for a single day, then it was possible that I could do it for everyday. I resolved to make it a daily thing, and I’ve been getting to work at 6am since.

The benefits magnified when I wasn’t under the pressure to get everything done before 7am as well. Being the first to get into the office meant that I had to make the coffee, but that meant that I could make it and get the first cup, and enjoy a bunch of uninterrupted time. As many people have noted, programmers like myself abhor the interruptions of a normal office environment, and it as been stated that it might even be a 15 minute setback every time someone asks a “quick question” because you need to get back “into the zone”.

Another benefit is leaving earlier from work, because I still usually stay for my prescribed 9.5-10 hours, which leaves a decent chunk of time between leaving time at work and the time when most things are scheduled at night. Having those two hours between “get home” and “social time” makes it a lot easier to work on my thesis, or get some consulting work done, making my day more accomplished even when I do have something to do in the evening, instead of having to set aside whole nights of my schedule for those activities.

There are a couple of things that could threaten this early wake-up time. If Diana doesn’t like it in the long run, or it’s too disturbing to her sleep cycle for me to get up at such an early time, it’s a no go of course. If people at work start complaining, I might push back a little bit saying that I get the uninterrupted time, but if they are a little insistent I’ll probably cave and switch back to a 7am show-up time. It might start grinding on me differently than it is now, and I could decide to change my habits on my own again. For now, it seems like I’ve stumbled into an early riser habit.

Liquid error: undefined method `titlecase’ for 11111:Fixnum

So today I seem to have survived another cycle around Sol, so now I’m one year older than last year. It hasn’t been a bad year overall. In the last year I’ve done a bunch of things:

  • Quit my job at Honeywell, and went to work full-time at a startup that I helped co-found. I’m a programmer there doing basically all of the programming they need to do. It’s much more rewarding to me than the other job was.
  • Put some of my hobby work on my github, Gatherling, a php project that I inherited and then put a bunch of work into which helps track free tournaments on Magic Online, and unsilent-assistant, a bot written for hosting those tournaments.
  • Hosted 37 free tournaments on Magic Online, providing prizes and having a bunch of fun playing virtual cards with real people.
  • Made over 500 commits to various git repositories, touching a ton of lines of code, that I can’t be bothered to count right now.
  • Started an LLC (Base Zero, LLC) to contain my consulting, which has made me some side money that is nothing to scoff at.
  • Wrote 51 blog posts, including this one. Most of these were made in 2011 as part of my challenge to write more blog posts. There are more than 20,000 words in these posts.
  • Lost more than 50 pounds, which is supposedly a good thing, but I can’t really quantify changes in my life other than a diet change and clothes fitting looser.
  • Bought a new (used) car for us, and gave away the old (broken) one for charity.
  • Took a trip to Portland with my beautiful and wonderful wife and had a great time.

There is a bunch of stuff that I’m sure that I’ve forgotten and will remember later, or I just don’t have the time to find the stats on right now, or I’m leaving out because I just don’t want to be that public with my life story right now.

Of course, there are still things that I wish I would have done better, including getting my thesis completed and a Ph.D under my belt. I am still planning on finishing that, and hopefully this year. There is a lot of work still to be done for it, including the writing of it all, and the experiments that I need to complete. I need to get working on it more seriously.

Overall I think that the last year has gone decently. There were some ups and downs, but I am still for the most part happy and healthy, and making the money that is required to keep both of those on the right side of things. I’m hoping that part of my blogging this year will give me a better idea of what is going on when I start looking back and thinking about years past. I’ve got what could be termed a horrible memory for things.

For now however - What day is today? It’s Michael’s birthday! What a day for a birthday! Let’s all have some cake!

Movie Review: Paul

I went to see Paul this weekend with Diana, and we were treated to a completely empty theater. It seems kind of strange whenever this happens, like everyone else got tipped to a really bad review or something. To add to the confusion, during the previews the vertical stabilization or something went off on the projector, and it was jostling up and down giving me a headache. I missed the opening titles. Despite these hiccups, the movie was quite enjoyable.

Paul is a movie about a couple of english guys played by the often seen together Simon Pegg and Nick Frost, who also did B002HR1W1K and B0025VLEM0 together. They play classic sci-fi geeks who are going to comic con and then taking a extended RV trip to all of the famous places in conspiracy culture, like Area 51 and the black mailbox, While they are on their way, a mysterious black sedan crashes in front of them and they are introduced to Paul (voiced by Seth Rogen), a little green alien who is rude, unexpected, and has mysterious powers. He is also running from the law.

The rest of the movie follows them running from two sets of mysterious and funny agents, played quite well by strong supporting actors Jason Bateman, Bill Hader and Joe Lo Truglio. A chase across the country and some zany situations follow, and a couple of twists near the end keep the whole thing interesting.

I felt like Paul got a slow start, but it really worked it’s way into a groove and soon the laughs were coming regularly. Cledd and Pegg play against each other well, and the situations they get a little into the unbelievable, but the alien addition to the cast make the whole thing work really well. There’s also a lot of callbacks that are funny to the die-hard sci-fi fan, but out of the way to the person who wouldn’t notice it. An example is the cantina band song from Star Wars being played in a country-western manner in one scene. It enhances the movie for those in the know but the whole scene is still hilarious without being tipped off.

Going out of this movie, I found myself unhappy that we were the only two who were seeing it that night - it certainly deserves to have an audience. I’d rate it at a 7.

Two RSS Reader Features I Would Like

More than a year ago I wrote a couple posts about Cullect, currently the best RSS reader that I’ve ever used. Since it’s shut off, I’ve had to make due with Google Reader for all of my RSS needs, since it’s the next best thing. Since then, I’ve been thinking about building my own reader and thinking about features that I would love to have in a reader.

The first is OPML subscriptions. For a while now, I’ve tried to follow a number of blog aggregates, including Planet Debian, Planet Ruby on Rails, and a couple others. Many of them include a OPML download of all of the feeds in the planet, in order to make it easy to subscribe to all of them at once. The model for this would be a number of source feeds going into a single node, and then a single RSS feed coming out. You can follow the planet’s RSS feed and see all of the items from all of the feeds, or you can use the OPML list to subscribe to all of the sources. I would like to have a reader that would periodically poll the OPML download, and add or remove the feeds that were added or removed from the planet. Ideally it would also tell me what I was subscribed or unsubscribed from.

The second is Link collections. I’ve been following the Hacker News Firehose Feed, and a number of other tech blogs. Because it’s the firehose feed, there are a lot of links submitted, and a lot of them are duplicates. Some of these links are pointing to items that I will see later, or have seen before, or items that I have already read. The feed reader should be smarter about the items that it shows to me, analyzing the links that they point to and grouping them together. Ideally it would try to find the end of those links, and show me the most relevant feed item, along with hiding the ones that just point to the most relevant one, and marking them all as read when I read the item. For bonus points, it can mark new items as read if all they do is point to the item that I’ve already read.

I am fairly sure that Link collections are more useful than OPML subscriptions, and they would actually also provide some important data about which items are the most important. It’s also possible that this type of analysis is not being done because it requires too much processing power. If we look at the importance angle, it suddenly sounds very similar to PageRank. I am not sure if I will ever get around to making that RSS reader, but if I do, it will definitely have both of these features.

Project 52: Week 13

Experimentation

Astute readers of my blog might have noticed a change in content in the month of March. Five times a week I was writing short fictions and posting them here, for all of the 10 readers to see and read and enjoy. I wasn’t really doing it for any reason except for experimentation.

Lately I’ve been playing a game online with a few online acquaintances. It’s a website called Health Month, a little site by Buster Benson, the same guy who did 750words which helps people write words every day. The website makes a game out of doing things every day which might improve your health. At the beginning of the month you choose your rules and you’re placed into a level, organized by how many rules you have and how hard they are. Rules are hard or difficult based on how hard you say they are as well as how important they are for you.

Over the last three months I’ve been playing with about 10 rules. As an example my rules for March were:

  • Creative Writing of at least 250 words at least 5 days a week (the fiction posts)
  • Take a multivitamin every day
  • Floss at least 5 days a week
  • Allow 1 soda a week
  • Eat breakfast every day
  • Allow 4 cups of coffee a week
  • Read a book for at least 30 minutes 3 days a week
  • Exercise for 30 minutes at least 5 days a week
  • Drink at least 58 glasses of water a week
  • Meditate for 30 minutes at least 5 days a week
  • Stay under my recommended daily calories every day
  • Do meaningful work at least 3 days a week
  • Study Human Robot Interaction papers at least 5 days a week

(You might notice that last rule is a little specific to me. It’s a custom rule, everyone can put in a custom do or don’t rule.)

Health Month is the gamification of habits, which is why I like it. You start with 10 life points, and you lose a point for every day that you don’t do one of your things - for every one of your things. If I went over calories, didn’t read, and missed meditation, I would lose three life points. People can give you life points if you plead for leniency, and you set rewards and penalties if you end the month with less than 1 life left.

I have really been enjoying playing, there is a group that I am in and we all encourage each other when we get down and also help each other out with healing each other’s life points.

I think that I enjoy Health Month so much because it makes it easy to set up month long experiments, like last month’s fiction writing, as well as focus on things that you should be doing every day like the flossing or limiting my cups of coffee.

I’ve been prone to doing these month long experimentations to myself in the past - for example last year I spent a month recording everything that I did in Field Notes notebook, and I switched up the exercises monthly before that trying to find a good route for walks, or finding a way to entertain myself in the gym. Experimentation is just part of my nature in this way, and it’s one of the ways that I strive to make my life more happy. If I try something for a month and it makes my life happier, then I will keep doing it. If it doesn’t work out, I only did it for a month, and I can say that I’ve really tried it and it wasn’t for me.

This month’s writing rule is to keep updating this blog, this time with meaningful blog posts instead of random fictions from my head. Let’s see if I can keep my points.

April Diet Update

So the diet has been going pretty well this month, I’ve been keeping to my calorie counts more and also not having as much of an issue with keeping the weight off. There are less ups and downs and that is a good thing. I still have some days when I weigh mysteriously three pounds more than I did the day before, despite only eating the prescribed amounts. I’m doing pretty good at just letting it go by though.

My daily diet has changed a little since the last time that I wrote. I cut all of the carbs out of my breakfast about halfway through March, partially to lower the caloric content of the meal, and partly because I was planning on trying a low-carb diet starting this month. I’ve started and been on the diet a week or so right now, and it’s been pretty good. Most days I’m trying to figure out how I can get to my calorie limit instead of seeing how I can get under it. Especially on days when I am exercising, I usually have to down an ounce or three of peanuts to make my calorie deficit goal.

Speaking of the exercise, it’s been pretty good to get back to it after taking the month of February off. I’m going five days a week for thirty minutes now, and that seems to be a sweet spot for me in terms of time taken and enjoyent. One of the things that I was really unhappy during exercise in the winter was the hour long sessions really dragged on my psyche. I always would be thinking about what I could be doing instead of exercising. I re-started with thirty minute sessions instead which was a great call - they are much easier to fit into a day because if I only have an hour free I can still fit in a workout, and I don’t have an issue finishing them. I also feel a lot more accomplished when I go a little extra, going 40 minutes or 45 minutes.

I don’t remember the exact cheat days that I took in March, but I’m sure that I was on form. It took a little bit longer to institute the “practice days” that I talked about last month - I had my first one last weekend as I was on a short day trip out of town. I ate like a “normal” day and ordered off the menu as if I wasn’t on a special diet and wasn’t sweating the calories. I think I came in just under the amount of calories I wanted.

I’ve been thinking lately that it’s more important how you feel about how you ate on the practice day instead of how you actually did on the calories. I know that when I was having too much food at lunch and then again having too much food at dinner, I was actually not happy with myself when I was finishing the meal, but I would keep on going because I wanted to finish the food that I had ordered, and I didn’t want to waste something. Alternately I was unhappy an hour later or later in the day when I was eating my dinner but realizing that I wasn’t actually hungry and I was just eating because it was good to eat with my wife for a dinner. It is most important to me on those practice days that I don’t have those feelings at all. Secondary feelings to avoid would be the ones where I feel over-full, like I have had too much to eat. I used to have that feeling all the time, and I barely ever have it now except on cheat days and practice days.

The thirty day graph looks good from here. It’s the best weekly loss number since I’ve started making these posts monthly. I’m dangerously close to the two pounds a week that I’ve been trying to hit since I’ve started logging my weight again. I’m also doing it by hitting my calorie goal now and not shorting it by 200 like I mentioned last month. That’s fine. I only had a day or two above the trend line, although I got closea few times.

The yearly chart looks pretty damn good as well. You can really see the trendline take the dip that I was hoping during the end of March. There is a nice number at the bottom of the y-axis too, I’m hovering around 270 now, making the mini goal that I had made before. I’m hoping to be hovering around 260 when I make the next report. I’m still aiming for 250 by the middle of this year, and then I will be making the big decisions about whether I’m stopping at that number, or if I will keep going. I never really had some solid goals when I started this whole thing, except for being a healthier person in general.