Skip to content

Instantly share code, notes, and snippets.

View ChickenProp's full-sized avatar

Phil Hazelden ChickenProp

View GitHub Profile
@ChickenProp
ChickenProp / Main.hs
Last active April 2, 2022 19:53
Exploring variadic functions in Haskell
-- See: http://reasonableapproximation.net/2022/04/02/variadic-hm.html
{-# LANGUAGE AllowAmbiguousTypes
, ConstraintKinds
, DataKinds
, FlexibleInstances
, FunctionalDependencies
, KindSignatures
, PolyKinds
, ScopedTypeVariables
@ChickenProp
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
ChickenProp / gist:3050085
Created July 4, 2012 23:35
Simple Raspberry Pi GPIO example

Introduction

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.
@ChickenProp
ChickenProp / README.md
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.

Summary

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.

Design

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