Playing (cards) with Clojure

I’m learning Clojure, which is a modern Lisp, which is hosted on the JVM. I’m so far really liking the focus on integrating the benefits of functional programming into a modern environment. It is pragmatic and reasonable. It feels like programming for grown-ups, in the same way that Node.js feels like programming for people with more energy than sense. While riding on the train with my kids, I told them, “Hey, I’m learning this new language, let’s use it to make a card game since we don’t have any cards with us.” Clojure, as a Lisp, is meant to be usable interactively from a REPL and since I was on my phone in a train, I used an in-browser version of Clojure called ClojureScript. The one I used is at http://trycojure.org. ...

February 21, 2024 · 6 min · jra

I'm still here...

While I was working for the DEDIS lab at EPFL, I was not writing here. Now I’m a dad at home, at least until my youngest starts school in a year, and so I’m still not writing here. I work at Pie Aéronefs, where I do various kinds of open source work, most of it on GitHub. When I’ve got my head fully back into the kinds of things I like to write about here, I’ll write again. ...

September 13, 2021 · 1 min · jra

Protecting private keys in Go

Today I was looking at Upspin and thinking about private keys. I asked myself, “what would it take to make sure that there was one single copy of the private key in RAM, and that Go and the OS worked together to make sure it never went onto disk?” (Some other people have talked about this too.) It turns out the answer to that question is much harder than expected, but doable and I’ll try to do it. ...

July 24, 2017 · 4 min · jra

My first ever Rust program!

Here, for posterity, is my first ever Rust program. It checks the key log on the Upspin Key Server. extern crate sha2; extern crate reqwest; use std::io::Read; use sha2::{Sha256, Digest}; fn main() { let mut resp = match reqwest::get("https://key.upspin.io/log") { Ok(resp) => resp, Err(e) => panic!(e), }; assert!(resp.status().is_success()); let mut content = String::new(); match resp.read_to_string(&mut content) { Ok(_) => {} Err(e) => panic!(e), } let mut hasher = Sha256::default(); let mut ct = 0; let mut last_hash = "".to_string(); for line in content.lines() { if line.starts_with("SHA256:") { let mut fields = line.split(":"); // skip first token match fields.next() { Some(_) => {} _ => { println!("Bad SHA256 line: {}", line); continue; } }; last_hash = fields.next().unwrap().to_string(); let expected = string_to_u8_array(&last_hash); let output = hasher.result(); assert_eq!(output.as_slice(), expected.as_slice()); } else { hasher = Sha256::default(); hasher.input(line.as_bytes()); let newline = "\n".as_bytes(); hasher.input(newline); if last_hash != "" { hasher.input(last_hash.as_bytes()); } } ct += 1; println!("Line {}", ct); } } use std::u8; fn string_to_u8_array(hex: &String) -> Vec { // Make vector of bytes from octets let mut bytes = Vec::new(); for i in 0..(hex.len() / 2) { let res = u8::from_str_radix(&hex[2 * i..2 * i + 2], 16); match res { Ok(v) => bytes.push(v), Err(e) => { println!("Problem with hex: {}", e); return bytes; } }; } return bytes; } I found myself sprinkling mut’s and unpack()’s here and there like the mutation unpacking fairy, hoping something would work. I don’t think that how you are supposed to do it, but we’ll see. ...

July 21, 2017 · 3 min · jra

Read it and weep

I searched for “how do I make an HTTP request in Rust?”. I’m a newbie, we do things like that. Don’t judge. I found this. I still don’t know how, because the answer marked correct refers to a library that a comment from 2016 informs me is no longer supported. There’s also a helpful comment pointing me at cURL, which is written in C, which is the opposite of safe. It does appear that the right answer, in 2017, is hyper. ...

July 21, 2017 · 1 min · jra

A Go programmer continues to learn Rust

I went looking for the equivalent of goimports and didn’t find it. Sad. I wanted to use std::fmt to do the same thing as sprintf or fmt.Sprintf. I got stuck on “expected &str, found struct `std::string::String`”. I found a blog posting trying to explain it but I don’t understand enough yet to understand it. What I do understand is that it is highly suspicious that a language has two incompatible types for string. WTF, Rust? I’m trying to write a program here and you want me to sprinkle magic to_string()s in it? How about you STFU and let me be a human, and you be the computer doing the boring crap for me? ...

July 18, 2017 · 2 min · jra

A Go programmer's first day with Rust

Where is the tutorial? The first Google hit gives a redirect to a page explaining that I should read the book. The first page of the book explains that I should read the Second Edition unless I want to go deep, then I should later read the First Edition also (and presumably ignore the things that had been changed later in the Second Edition?) OK, let’s do this thing! Get rust-mode installed in Emacs, and get it to call rustfmt on save, because Go taught me that the tab button is from 1960 and I don’t use it anymore. ...

July 17, 2017 · 2 min · jra

bzr is the Windows of VCS

That is all.

July 13, 2017 · 1 min · jra

Python keyword "finally" trumps "return"

Here is a piece of Python that I did not expect to surprise me: def a(): try: raise 1 return 1 except: print "exception!" return 2 finally: return 3 print a() In both Python 2.7 and Python 3, that prints: exception! 3 It seems that in Python, return is just a casual suggestion to the interpreter, and finally gets to decide, “Nope! Your return is canceled and I will do my return instead!” Now, to be fair, in Go a defer can change the return value of a function as well. But the defer keyword literally does what it says on the tin, it defers some work until after the return, so you can reason about why it might be changing the return value. ...

July 10, 2017 · 1 min · jra

Job Searching

I’m looking for a job that will help me reduce my commute, and get the chance to touch new fascinating things. Here’s a post from last time I was looking for a job, which shows some work samples I am proud of. If any of my readers can hook me up with interesting job postings, I’d be grateful.

June 15, 2017 · 1 min · jra