## Install Postgresql 9.2 on Debian Squeeze

I was getting the following errors because the squeeze packages are too old for 9.2:

The following packages have unmet dependencies:
postgresql-9.1 : Depends: libpq5 (>= 9.1~) but 8.4.13-0squeeze1 is to be installed
Depends: postgresql-client-9.1 but it is not going to be installed
Depends: postgresql-common (>= 115~) but 113+squeeze1 is to be installed


These are the steps I took to get postgresql 9.2 running on debian squeeze:

deb http://backports.debian.org/debian-backports squeeze-backports main
sudo apt-get update
sudo apt-get -t squeeze-backports install libpq5 postgresql-common


Add the postgresql repo to /etc/apt/sources.list:

deb http://pgapt.debian.net/ squeeze-pgdg main 9.0 9.2
sudo apt-get update
sudo apt-get install postgresql-9.2


Instructions have changed a bit, check out https://wiki.postgresql.org/wiki/Apt

## Making Drupal 7 ViewsSlideshow Pager Clickable

While setting up a homepage slider, I used a modified version of the solutions found here. The solution provided worked great, except I needed a clickable version.

Create a new template called views-slideshow-slide-counter.tpl.php (notice that I changed it from above as I needed the ID to make the click work):



<?php
$slide_count = count($view->result);
for($i=1;$i<=$slide_count;++$i) {
$n =$i - 1;
$active =$i == 1 ? 'active' : '';
print '  ';
}
?>



In application.js:

(function($) {$(document).ready(function() {

Drupal.viewsSlideshowSlideCounter.transitionBegin = function (options) {
$('#views_slideshow_slide_counter_' + options.slideshowID + ' span').removeClass('active');$('#views_slideshow_slide_counter_' + options.slideshowID + ' .num' + (options.slideNum + 1)).addClass('active');
};

$('.slide-block').click(function() { var id =$(this).attr('id').split('-').pop();
var options = {'action': 'goToSlide', 'slideshowID': 'homepage_slider-block', 'slideNum': parseInt(id)};
Drupal.viewsSlideshow.action(options);
});

});
})(jQuery);


Hope this helps someone trying to figure out how to make the pager clickable.

## Superbowl 0-9 Pool Last Digit Frequency

If you’re in a 0-9 pool, where the total of the game scores last digit determines if you win, you may be interested in the history of your number. Here is a plot showing the frequency of the last digit from superbowls between 1968-2011.

## The Forgotten Man

“As soon as A observes something which seems to him to be wrong, from which X is suffering, A talks it over with B, and A and B then propose to get a law passed to remedy the evil and help X. Their law always proposes to determine what C shall do for X or, in the better case, what A, B and C shall do for X. As for A and B, who get a law to make themselves do for X what they are willing to do for him, we have nothing to say except that they might better have done it without any law, but what I want to do is to look up C. I want to show you what manner of man he is. I call him the Forgotten Man. Perhaps the appellation is not strictly correct. He is the man who never is thought of. He is the victim of the reformer, social speculator and philanthropist, and I hope to show you before I get through that he deserves your notice both for his character and for the many burdens which are laid upon him.”

See the whole article

## Good advice from Daniel Kahneman

I think academia would be a better place and with a little less ego if we all followed your lead on this! Finally, you’re working on well-being now. What can we do to boost our well-being?
I can think of three things. First, change the way you use your time. Time is the ultimate finite resource – we should use it as if it is. Second, try to pay attention to the things that make your life better rather than concentrating on the things that make your life worse. And the third I think is to invest your time on activities that you will continue to pay attention to. For example when people buy a car they imagine themselves driving the car and enjoying it. But most of the time when you actually own the car and are driving it you’re not attending to it. However, when you are socialising with friends you are attending to that activity. So there are activities that are attention-rich intrinsically. If there are good activities that are attention rich you should work on them – you should try to have a lot of them in your life. I think people don’t do that enough.

## Creating snapshots on AWS with ruby and awstools

Since the recent outage, I’ve been looking for simple scripts to take a snapshot of a volume and only keep a certain number of these snapshots around. I wanted something that I could run from cron in different intervals for different volumes. I found a few scripts lying around, none of which I really liked so I decided to put together one in ruby.

I created the awstools gem, submitted a patch to amazon-ec2 to allow filter requests on the snapshot api and now I have the tool I was looking for.

Check it out here and let me know what you think.

Until my patch is accepted you’ll have to use my fork of the amazon-ec2 gem. Which means you’ll have to clone it to your machine, build the gem with “gem build amazon-ec2.gemspec” then install that gem with “gem install amazon-ec2…”.

To install awstools

gem install awstools


Or to build it yourself, clone the repo to your machine, and then run:

cd awstools
bundle
gem build awstools.gemspec
gem install awstools-0.0.1.gem


Once installed you can run something like the following from cron:

0 0 * * * snapshots -v volume-id -d "Some Description" -k 2


That will take a snapshot once a day and only keep two snapshots on hand.

Note that there is an -s flag to simulate, so you can see what it will actually do without creating or deleting any snapshots.

If you see all the volumes at amazon fly by, its because you aren’t using my fork of amazon-ec2.

## Using emacs to post to your blog

I’ve recently started playing with emacs (again). One feature that I just tried out is weblogger mode. It allows you to post entries to your blog directly from emacs using xmlrpc. Very simple setup. Since I’m using elpa, I can do a M-x package-list-packages, select weblogger to install and install it. Once installed you simply run M-x weblogger-setup-weblog, provide the credentials and are connect to your blog.

Check out the docs over at the Emacs Wiki

To be honest, the only reason I wrote the post was to test posting from emacs!

## Autotest keeps running

I had an issue with autotest where the tests would just keep running, even when all the tests passed. After doing some searching I found the following code helpful from this post:

Put this in your ~/.autotest, leave out the growl line if you’re not using that.

require 'autotest/growl'

end


When I initially tried this code it didn’t work. To figure out why autotest thought it had to keep running I ran the following:

find ./ -cmin -1


This will show you any files that changed in the last minute. I had to add db, log, system and public to the list above. Depending on your configuration you might run into other files or folders that need to be excluded.

## Before You Bet, Understand Expected Value!

With the upcoming super-bowl and all the betting surrounding it, you should understand expected value before you make any bets.

Informally, the expected value can be interpreted as the long-run average of the results of many independent repetitions of an experiment. (from wikipedia)

By using expected value as a guide over your life, you should come out ahead.

How to calculate expected value:

Say you have two options, one is to bet in a superbowl grid and the other is to bet on a 0-9 pool. To calculate the expected value of each do the following:

Expected Value = – (chance of losing * amount lost) + (chance of winning * amount won)

Ex. -(.99 * $100) + (.01 *$10,000) = $1 (Superbowl Grid) (The above is simplified as with the grid you have a .01 chance of winning each quarter and for the half) Ex. -(.9 *$100) + (.1 * $1,000) =$10 (0-9 pool)

Which would be the better choice?

In most decisions in life you would prefer the expected value be more than the amount at risk, this rarely happens with betting and is the reason the house always wins.

## Issue using insert_after/before “ActionDispatch::Static”

We are currently building a new product on Rails 3 with a couple custom middleware rack apps. Everything is working great on development and we’re progressing nicely. Today I decided to start setting up the production environment and the following error popped up:

No such middleware to insert after: "ActionDispatch::Static"


I had this in my config/application.rb:

config.middleware.insert_after('ActionDispatch::Static', '::API::Throttle')


I received this error while trying to run rake or startup unicorn. After looking around trying to figure out what I was doing wrong I discovered this in the production config.

config.serve_static_assets = false


Essentially what this does is remove “ActionDispatch::Static” from the rails middleware stack. I had no idea that I could not rely on that being there.

config.middleware.insert_before('Rack::Lock', '::API::Throttle')