error: ‘NAN’ undeclared when installing igraph

I got this strange error when installing igraph:

plfit/gss.c: In function ‘gss’:
plfit/gss.c:92: error: ‘NAN’ undeclared (first use in this function)
plfit/gss.c:92: error: (Each undeclared identifier is reported only once
plfit/gss.c:92: error: for each function it appears in.)
plfit/gss.c:93: error: ‘INFINITY’ undeclared (first use in this function)

It turns out to be a compiler standard problem. Adding the flag CFLAGS=’-std=gnu99′ to make solves the problem


set Mac for python

Update: Now I would recommend just anaconda python

To be cool in a coffee shop I bought a mac and then I become dumb at work.

Gladly I find these tips on setting up a mac for python

easy_install does not work after distribute upgrade

I tried to upgrade matplotlib which asked me to upgrade distribute. I upgraded distribute and then easy_install does not work…… It is solved by the following

1. Check your /usr/bin and /usr/local/bin for easy_install installations and remove any old script:

sudo rm /usr/bin/easy_install*

sudo rm /usr/local/bin/easy_install*

2. Download and run distribute:

curl -O

sudo python

sudo rm

Copy from

Sample with replacement

random.sample() samples without replacement. I find this piece of code by Sean Ross which samples with replacement.

# credit author(s) of
import random
import itertools

def sample_wr(population, k):
    "Chooses k random elements (with replacement) from a population"
    n = len(population)
    _random, _int = random.random, int  # speed hack 
    return [population[_int(_random() * n)] for i in itertools.repeat(None, k)]