There is a promising measure on the Oregon ballot this year, Measure 90.

If Measure 90 passes, it would replace the primary election system that is currently in place. Right now, voters must register with a political party first, and then vote for candidates in that party in the primary elections. The winners for the primary for each party then go on to the general election.

One huge problem with this approach is that voters must commit to a single party for the primary election. This means that it is not possible to vote for a senator in one party and a governor in a different party. I’ve written before that I don’t think political parties are anything more than loosely organized tribal groups.

This also limits the ability for smaller parties (Independent, Green Party, Libertarian, etc.) to elect candidates, because in the primaries, voters must register with a party first. So if that person wants to vote for a few Democrats and a Green, or a few Republicans and a Libertarian, they would have to choose only one party and neglect the others. This tends to support the dominant parties, Republicans and Democrats, since they are the most numerous. There is a rational way to calculate the most effective tradeoff, but there is a better way.

Having to choose a party, and then choose a representative adds more layers between the citizen and the laws that ultimately passed. Right now, us citizens don’t vote directly on most laws, we elect representatives to do that for us. And without open primaries, we also cede even more power to the existing parties, instead, we should ignore parties and just vote for the representatives directly.

This is a great opportunity for Oregon residents to strip out an unnecessary layer of indirection from the election process, if you care about ending the Democratic/Republican-dominated primary elections, vote yes on Measure 90.

The gini coefficient is a measure of income inequality. It is calculated by ordering the given population by income, then calculating the cumulative distribution, and finding out how much it deviates from total equality.

So for example, assume there are four people, and everyone makes the exact same amount:

Then, the cumulative distribution just sums the values to the left, so for this hypothetical equal society of four, the cumulative distribution would look like this:

So, as you can see, the cumulative distribution would be a straight line. The gini coefficient is calculated as two times the area of the difference between this straight line and the actual distribution. Since in this hypothetical world, the distribution is totally equal, it follows that the gini coefficient is 0.

The way to read the gini coefficient is that 0 is totally equal, and 1 is totally unequal. In the totally unequal case, one person would make everything, and everyone else would make nothing:

As is probably obvious at this point, the gini coefficient can be any real number between 0 and 1, with lower meaning more equal, and higher meaning less equal.

However, reality is always more interesting (and messier). The real world gini coefficient in 2014 of the United States 0.42, and Switzerland is 0.31

By modeling the cumulative distribution function as a power, such as xn, you can find an n that reproduces the same gini coefficient:

In 2013, the United States had a gini coefficient of 0.42, which corresponds to a distribution curve that is about x2.45, by contrast, Switzerland has a gini coefficient of 0.31, which corresponds to a distribution curve that is about x1.9

It’s important to note that the cumulative distribution function is most likely not a simple power, but this shape does give a decent guess at what the respective distributions might look like.

Also, the gini coefficient says nothing about the absolute standard of living, meaning that a rich country and a poor country could have the same gini coefficient. For example, Norway and Czech Republic both have a gini coefficient of about 0.25, but Norway’s GDP per capita is about 5 times more than Czech Republic’s.

Given these limitations, the gini coefficient is a useful number for getting an idea about how income is distributed in a given population.

At work I have an adjustible-height desk, that way it can be both a standing or a sitting desk. In order to better understand my own usage habits, I made the desk script, which logs state transitions.

Running desk up records the time that the desk was moved up into a standing position, and desk down records the time the desk was moved into the sitting position. Later, when I have a few months of data, I’ll do some analysis and see what the probabilities are in the following state transition diagram:

The script builds a CSV file, and implements a simple interface:

1
2
3
desk up    # log transition to "up" state at current time
desk down  # log transition to "down" state at current time
desk log   # show last 5 state transitions along with time

Here’s the source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
log_filename="/path/to/log/file"

function create_log_file_if_not_exists {
  if [ ! -e $log_filename ]
  then
    echo "timestamp,state" > $log_filename
  fi
}

function log_new_state {
  create_log_file_if_not_exists

  local state=$1
  local timestamp=$(date --iso-8601=seconds)

  echo "$timestamp,$state" >> $log_filename
}

function show_log {
  create_log_file_if_not_exists

  echo "timestamp                 state"
  awk < $log_filename -F, 'NR > 1 {print $1"  "$2}' | tail -5
}

if [ $1 = "up" ] || [ $1 = "down" ]
then
  log_new_state $1
elif [ $1 = "log" ]
then
  show_log
else
  echo "Invalid command: $1"
  exit 1
fi

This will allow me to use a Markov chain to model my sitting/standing habits. More on markov chains in a later blog post.

On the health benefits (or problems) with standing, I am not a medical professional, but I think alternating sitting and standing is probably better than all sitting or all standing.

When working on rails apps, I usually have to make a mental map of the models and how they interrelate.

An Active Record model can belong to another, but when you have more than half a dozen models, keeping all the belongs_to relations in mind quickly becomes impossible. As a solution to this, I made a command line program called argraph, for ‘ActiveRecord graph’, it produces a digraph in the DOT language, which can be rendered as an image using GraphViz.

The nodes are models, and the edges are the ‘belongs to’ relation.

The way to use it is to check it out or fork my bin repo, make sure that directory is in your PATH variable, cd to the root of your rails app and run argraph.

As an example, suppose you have the discourse rails app checked out, and you want to find out how some of it’s models are interrelated:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ cd discourse
$ argraph Post Topic Category PostReply User UserAction UserHistory QuotedPost View UserAvatar
digraph {
 Post -> User
 Post -> Topic
 Topic -> Category
 Topic -> User
 Category -> Topic
 Category -> User
 PostReply -> Post
 UserAction -> User
 QuotedPost -> Post
 QuotedPost -> QuotedPost
 View -> User
 UserAvatar -> User
}
$ !! | dot -Tpng > discourse.png

The above graph renders as: discourse model graph

You can also run the command with no arguments, in which case it maps out all models, but on bigger apps, this can be hard to follow, so I found it useful to be able to explore subgraphs containing more models than my memory could fit, but not so many that the image was polluted and hard to follow.