I hereby claim:
- I am chickenprop on github.
- I am philh (https://keybase.io/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:
I hereby claim:
To claim this, I am signing this object:
The point of this post is an attempt to calculate e to given precision in bash, a challenge given in a job listing that I saw recently. I kind of got nerd sniped. I wrote this as I went along, so there may be inconsistencies.
The obvious method to compute e is as the infinite sum of 1/n!, n from 0 to ∞. This converges quickly, but how far do we have to calculate to get the n'th digit of e? We can deal with that later.
We obviously need a factorial function.
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 used to complain about being out of date, and ask if I wanted to upgrade; and it would complain about
systemd-tools both wanting to own
udev. (I no longer remember exactly what the errors were.)
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
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
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?
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
=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.
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.)
The recent post on Hacker News about #! semantics surprised me. I had always assumed that a shebang line like
#! /usr/bin/prog -a -b
Would be equivalent to calling
$ /usr/bin/prog -a -b <file>
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
My root filesystem is on an SD card, and when I got a Raspberry Pi I decided to swap that SD card for a larger one and use the original in the Pi. This post chronicles my attempts to copy the filesystem.
I only have one SD card slot, which means I need to copy through an intermediate storage device. I have a backup disk, so that's not a problem. I also need another operating system, since I can't use my normal one while copying things to the new SD card. (I also no longer have the original OS on my netbook, because I've been using that partition for swap space.) Years ago I put a copy of Ubuntu on a USB stick "in case of emergencies" (I think this is the first time I've needed it), so that's not a problem either.
The new SD card already has one full-size partition, so the first step is to install ext3 on it:
After installing Arch on my Raspberry Pi, internet worked out of the box: I could plug it into the router, turn it on, ssh in and start downloading things. But the router is in my housemate's bedroom, which isn't ideal. If I want the Pi to be connected to the internet in my room, I need it to be connected to my laptop. (Another option would be a USB wifi dongle, of course.) This is how I did it. Much credit goes to the Ubuntu wiki's Connection sharing page.
I should disclaim that I don't fully understand networking stuff, and some of what I say might be wrong. I also didn't write this as I was going; so while I've consulted my browser and shell histories, it's possible I've forgotten some steps.
My laptop is running Gentoo, and this is where most of the work has to be done. It connects to the internet through wifi, on interface
wlan0. The ethernet port is
eth0 is also the name of the ethernet port on the Pi.
Step zero: plug ev