Slow ipython in osx yosemite?

Seems AppNap puts ipython to sleep, try this to disable it:

defaults write org.python.python NSAppSleepDisabled -bool YES

Zero to One – Peter Thiel & Blake Masters


Bottom line, if you’re in business, invest in business, thinking about starting a company or are currently starting a company, you should read this book!

The premise of the book is that you have to control your destiny, do not depend on luck and do not think it will happen automatically. Creating a new business category happens only once, hence 0 to 1 (technology). Whereas incremental progress is 1 to n (globalization). Thiel outlines how to make that happen, drawing from his experience as one of the founders of PayPal and Palintir. He offers very good advice, but no magic bullet, because there are no magic bullets.

Brief chapter overviews:

In the 1999 crash, businesses learned the wrong lessons and they are still practicing them. They should have learned to be bold, plan, not enter competitive markets and put energy into distribution.

You must create a monopoly company. Monopolies are what drive the future as they allow founders to do long term planning vs. short term planning. Competition kills the ability to do long term planning so avoid it at all costs.

To build a monopoly company you need some combination of proprietary technology, network effects, economies of scale and branding.

You must take control of your future by planning for it, chance will not get you there.

Remember the power law, only a small percentage of companies can ever succeed at a substantial scale. When it comes to your own life think hard about what will be valuable in the future, then pursue that will everything you have.

To build a valuable company you have to do something nobody has done before. To do that you have to tap into secrets that aren’t already universally understood.

When starting a new company you have to start right and have committed founders that add value.

Company culture should be of like minded people with individual talents. Internal conflict will tear a startup apart.

It is essential to have distribution and count it as part of your initial design. A company that has a product without good distribution is doomed to failure.

The computer should be a complement to human activity, it should supplement decision making.

If you want a successful business you must answer the following questions:

Do you have a breakthrough technology? Why is now the right time? Are you starting with a big share of a small market? Do you have the right team? Do you have a way to deliver your product? Will your position be defensible for 10 – 20 years? Have you identified a unique opportunity that others don’t see?

Thiel’s overriding question is whether we will be able to escape from optimistic indefinite and get back to optimistic definite. To do this we must think for ourselves and build businesses that go from 0 to 1. I get the feeling Thiel isn’t so optimistic about this.

I thoroughly enjoyed Thiel’s book and feel that he shared some of his secrets with us. I also think it is important to move the dial back to doing some planning after moving so far toward indeterminism. Creating a unique technology is no doubt a difficult task, but it is what is needed to keep our society moving forward. As a country we need to create the proper incentives so that smart people work on hard problems instead of spending that intellectual capital in the markets. It should be just as attractive for someone with the capabilities to be a scientist or engineer as it is to be a Wall St. trader/analyst. How do we get there?

A special thanks the Zero to One team for the advanced reader’s copy!

Book Notes

Error installing python module that uses pbr

If you get the following error when running python install:

error in setup command: Error parsing somemodule/setup.cfg: OSError: [Errno 2] No such file or directory

It is because git is not installed. On debian apt-get install git-core and you should be all set.

Finding Apache Average Memory Usage on Debian Wheezy

I wanted to find the average process memory usage on Debian wheezy to calculate MaxClients.

I used this script to do it:

sudo ps -ef | grep apache2 | grep -v ^$USER | awk '{ print $2 '} | xargs sudo pmap -d | grep ^mapped: | awk '{ print $4 }' | cut -dK -f1 | awk '{SUM += $1} END { print SUM/NR }'

Quick explanation, starts out with a process list, filters for apache2, removes the grep command from the list, prints the second column, uses pmap to display memory usage, then grep to filter out the mapped memory. Again printing the fourth column, then using cut to remove the K, and awk to sum up the records. NR in awk is the number of input records seen so far.

To get MaxClients divide your total memory (minus some margin for other system processes) by the average process memory usage to get the number for MaxClients.

Example, 50K process size, memory of 1.8G, 1.8G/50K = 36

Note you shouldn’t use the ps VSZ as it includes shared memory.

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:

Add backports to /etc/apt/sources.list:

deb 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 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

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)};


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.
See the full article here.

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
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.