Skip to content

Instantly share code, notes, and snippets.

View ChickenProp's full-sized avatar

Phil Hazelden ChickenProp

View GitHub Profile
ChickenProp / Main.hs
Last active April 2, 2022 19:53
Exploring variadic functions in Haskell
-- See:
{-# LANGUAGE AllowAmbiguousTypes
, ConstraintKinds
, DataKinds
, FlexibleInstances
, FunctionalDependencies
, KindSignatures
, PolyKinds
, ScopedTypeVariables
ChickenProp /
Last active April 26, 2024 20:30
Political Polarization in the US House of Representatives

If you intend to fork this, please note that it contains my Google Analytics tracking code.


This is a visualization of political polarization in the US House of Representatives, as calculated by DW-NOMINATE. DW-NOMINATE allows one to calculate the political leaning of a member simply by comparing their voting record to others', ignoring their party affiliation and even the content of the bills they vote on.


My initial idea was to draw the career progression of every House member as a distinct path, color coded according to their party affiliation in any given congress. The user would also be able to select members to view detailed statistics about them. But when I implemented that, I discovered it was far too noisy. Trends were difficult to make out, few individual members were discernible, and the elements used to represent them were so small that they were almost impossible to select. Feedback #1 confirmed that this was

Keybase proof

I hereby claim:

  • I am chickenprop on github.
  • I am philh ( on keybase.
  • I have a public key whose fingerprint is 84A5 6F31 7B32 3DBD 160C 37E8 6EAA 563A 7D8D E4A4

To claim this, I am signing this object:

ChickenProp / gist:3805370
Created September 29, 2012 22:55
Piiwii - a Raspberry Pi-powered robot controlled by a Wii nunchuk

I turned my Raspberry Pi into a robot, controlled by a Wii nunchuk. It's surprisingly easy to do - at least, surprisingly to me, who has not previously made a robot. But because it's surprising, it might help others to have a guide, so here one is.


I'm linking to SKPang for most of these, but Sparkfun and Adafruit would be good places to look if you're in the US.

(If you're in the UK, a word of caution - I bought motors and some other stuff from Sparkfun to save £7 over SKPang, but the package got stopped at customs and I had to pay £4 VAT and £8 handling fees. My understanding is that this will only happen on packages whose contents are worth more than £15, but you'd be a fool to trust me on this. It didn't happen when I spent £20 at Adafruit or £5 at Sparkfun. YMMV.)

  • Raspberry Pi - for the robot logic. An Arduino or similar could be substituted (though the software would need to be rewritten).
ChickenProp / gist:3614309
Created September 3, 2012 22:47
Arduino and Gentoo

The Arduino wiki has a page on getting an Arduino to work with Gentoo. It didn't work for me, so I'm posting what did work here. I'm hesitant to put this on the wiki page directly, because it would require removing a lot of information that was put there for a reason. But, here's what seems to have worked for me. Caveats: I've only tested with an Uno and a Leonardo; and in the process of getting them to work, I did a lot of other things that I don't think made a difference, but I don't remember what half of them were, so who knows?

How to do it

  • Configure your kernel to enable Device Drivers -> USB support -> USB Modem (CDC ACM) support. If you're not sure whether you have it, run zgrep USB_ACM. If you do, there'll be a line CONFIG_USB_ACM=y or =m. It's okay to have as a module, and building a module is faster than recompiling your entire kernel and doesn't require a reboot. I'm not going to go into the process here, though.
  • Emerge avrdude and `a
ChickenProp / gist:3231712
Created August 2, 2012 00:02
Briefly: using an Adafruit LED Matrix with the Raspberry Pi

Adafruit sells an 8x8 LED matrix which you can control from a Raspberry Pi using I2C. Unfortunately they only provide Arduino code; I've only used I2C through the programs i2cset, i2cget, i2cdump and i2cdetect available from the i2c-tools package; and it wasn't immediately obvious how to use Adafruit's code to control the matrix from the Pi.

Fortunately, it turns out to be quite simple. i2c-tools seems to assume a register-based model of I2C devices, where the target device has up to 256 pointers which can be read and written. This doesn't seem to suit the HT16K33 chip (datasheet) that the matrix backpack uses. For example, when I ran i2cdump, which gets the value of each register, it started to blink a picture at me. At least I knew it was working.

Setting individual LEDs works much as you might expect. Every row has a single register, the eight bits of that register correspond to the eight LEDs on

ChickenProp / gist:3194723
Created July 28, 2012 20:45
The Liang-Barsky algorithm for line-rectangle collisions

The Liang-Barsky algorithm is a cheap way to find the intersection points between a line segment and an axis-aligned rectangle. It's a simple algorithm, but the resources I was pointed to didn't have particularly good explanations, so I tried to write a better one.

Consider a rectangle defined by x_min ≤ x ≤ x_max and y_min ≤ y ≤ y_max, and a line segment from (x_0, y_0) to (x_0 + Δ_x, y_0 + Δ_y). We'll be assuming at least one of Δ_x and Δ_y is nonzero.

Image depicting the situation

(I'm working with Flash, so I'll be using the convention that y increases as you go down.)

We want to distinguish between the following cases:

ChickenProp / gist:3183960
Created July 26, 2012 19:21
Expanding the Raspberry Pi's GPIO capabilities with the MCP23017


The MCP23017 is an I/O expander chip. It has 16 GPIO pins which you can control using an I2C interface using two pins from a Raspberry Pi, plus a power source and sink (which can also come from the Pi). It's not quite as simple as directly controlling the Pi's GPIO pins, but it's not complicated, either.

You need to install i2c-tools, which is probably in your distribution's package manager. You also need a kernel with I2C support; you might need to modprobe i2c-dev. It would presumably be possible to do without either of these things, and bitbang the I2C protocol over GPIO, but I don't understand the protocol well enough to try.

On pin numbering: if you like, you can refer to the datasheet for the MCP23017. There's a small dot in one corner of the chip, with a semi-circular cut-out at that end. The pin near

ChickenProp / gist:3059628
Created July 6, 2012 11:22
Arch RPi miscellany

Some notes on getting Arch to work on the RPi.


At first, running shutdown -r now would cause the RPi to halt but not restart. A firmware upgrade fixed this. Install git, then clone and run rpi-update. (The script requires git to run, so you can't just copy it from the repository.)

Pacman and udev

pacman used to complain about being out of date, and ask if I wanted to upgrade; and it would complain about udev-oxnas and systemd-tools both wanting to own udev. (I no longer remember exactly what the errors were.)

ChickenProp / gist:3050085
Created July 4, 2012 23:35
Simple Raspberry Pi GPIO example


This is a dead-simple way to test that GPIO on the Raspberry Pi is working. I have an SKPang Raspberry Pi starter kit A. But all you need is

  • A Raspberry Pi.
  • An LED.
  • A button.
  • A resistor, approximately 270Ω.
  • Some way to connect these to each other and the GPIO pins.