219 results for "":
Day 11 (Advent of Code 2022)
It’s a new day, it’s a new advent of code puzzle.
In that one, we have to apparently cosplay as an IBM mainframe and just.. crunch them numbers. This doesn’t look fun, and I can’t think of a clever twist to make it fun, so let’s try to make it short and sweet.
Parsing
Our input looks like this:
Monkey 0:
Starting items: 79, 98
Operation: new = old * 19
Test: divisible by 23
If true: throw to monkey 2
If false: throw to monkey 3
Monkey 1:
Starting items: 54, 65, 75, 74
Operation: new = old + 6
Test: divisible by 19
If true: throw to monkey 2
If false: throw to monkey 0
(etc)
Dynamic symbol resolution
2020 Retrospective
Against all odds, it looks like the year 2020 will actually come to an end - in less than a day now. I know! Hard to believe for me too.
A lot of things have happened for me personally, and professionally. It’s been a big year in many ways, and I feel like, to get some closure, I need to highlight some of them.
From “looking at graphs” to “driving to the hospital”
Highlighted code in slides
I have obsessed about this long enough, I think it’s only fair I (and you!) get some content out of it.
When I started writing this article, I was working on my P99 CONF slides. Those slides happen to include some bits of code. And because I’m a perfectionist, I would like this code to be syntax highlighted, like this:
let addr: SocketAddr = config.address.parse()?;
let ln = TcpListener::bind(&addr).await?;
info!("🦊 {}", config.base_url);
Serving ASCII cats over HTTP
Our catscii program does everything we want it to do, except that it’s a
command-line application rather than a web server. Let’s fix that.
Enter axum
The documentation for the axum crate tells us how to make a basic web server, and we honestly don’t need much more than that.
So let’s add axum:
amos@miles:~/catscii$ cargo add axum@0.6
Updating crates.io index
Adding axum =0.6 to dependencies.
Features:
+ form
+ http1
+ json
+ matched-path
+ original-uri
+ query
+ tokio
+ tower-log
- __private_docs
- headers
- http2
- macros
- multipart
- w
Async fn in trait... not
Async fn in trait… not
I was planning on showing the in-progress async_fn_in_trait feature in the
context of my website, but it turns out, I can’t!
My website uses two databases: one local SQLite database for content, and a shared Postgres database for user credentials, preferences etc. Migrations are run on startup, and each migration implements one of the following traits:
Parsing and serializing ICMP packets with cookie-factory.
In the last part, we’ve finally parsed some IPv4 packets. We even found a way to filter only IPv4 packets that contain ICMP packets.
There’s one thing we haven’t done though, and that’s verify their checksum. Folks could be sending us invalid IPv4 packets and we’d be parsing them like a fool!
This series is getting quite long, so let’s jump right into it.
Reading files the hard way - Part 1 (node.js, C, rust, strace)
Everybody knows how to use files. You just open up File Explorer, the Finder, or a File Manager, and bam - it’s chock-full of files. There’s folders and files as far as the eye can see. It’s a genuine filapalooza. I have never once heard someone complain there were not enough files on their computer.
But what is a file, really? And what does reading a file entail, exactly?
Doing geo-location and keeping analytics
I sold you on some additional functionality for catscii last chapter, and we
got caught up in private registry / docker shenanigans, so, now, let’s resume
web development as promised.
Adding geolocation
We kinda left the locat crate stubby, it doesn’t actually do any IP to
location lookups. It doesn’t even have a dependency on a crate that can do
that.
Aiming for correctness with types
The Nature weekly journal of science was first published in 1869. And after one and a half century, it has finally completed one cycle of carcinization, by publishing an article about the Rust programming language.
It’s a really good article.
What I liked about this article is that it didn’t just talk about performance, or even just memory safety - it also talked about correctness.