212 results for "":

The thumbnail for this page

Using the Shipyard private crate registry with Docker

Cool bear

Wait wait wait, so we’re not talking about nix yet?

Well, no! The service we have is pretty simple, and I want to complicate things a bit, to show how things would work in both the Dockerfile and the nix scenario.

And because I don’t like contrived examples, we’re going to do something somewhat real-world: we’re going to geo-locate visitors, and track how many visits we get from each country.

A Rust match made in hell

I often write pieces that showcase how well Rust can work for you, and how it can let you build powerful abstractions, and prevents you from making a bunch of mistakes.

If you read something like Some mistakes Rust doesn’t catch in isolation, it could seem as if I had only nice things to say about Rust, and it’s a perfect little fantasy land where nothing ever goes wrong.

The thumbnail for this page

Day 16 (Advent of Code 2022)

Let’s tackle the day 16 puzzle!

Parsing

The input looks like this:

Valve AA has flow rate=0; tunnels lead to valves DD, II, BB Valve BB has flow rate=13; tunnels lead to valves CC, AA Valve CC has flow rate=2; tunnels lead to valves DD, BB Valve DD has flow rate=20; tunnels lead to valves CC, AA, EE Valve EE has flow rate=3; tunnels lead to valves FF, DD Valve FF has flow rate=0; tunnels lead to valves EE, GG Valve GG has flow rate=0; tunnels lead to valves FF, HH Valve HH has flow rate=22; tunnel leads to valve GG Valve II has flow rate=0; tunnels lead to valves AA, JJ Valve JJ has flow rate=21; tunnel leads to valve II
Exclusive content The thumbnail for this page

The promise of Rust

The part that makes Rust scary is the part that makes it unique.

And it’s also what I miss in other programming languages — let me explain!

Rust syntax starts simple.

This function prints a number:

fn show(n: i64) { println!("n = {n}"); }

And this program calls that function — it looks like any C-family language so far, we got parentheses, we got curly brackets, we got, uhh…

The thumbnail for this page

Day 13 (Advent of Code 2020)

In the Day 13 problem, we’re trying to take the bus.

Our input looks like this:

939 7,13,x,x,59,x,31,19

The first line indicates the earliest minute we can leave from the bus terminal, and the second line indicates the “identifier” of the buses that are active.

Each bus departs every “bus ID” minutes - bus 7 leaves at minute 0, minute 7, minute 14, minute 21, etc. The question is: which bus can we take first (apparently they either all go to the same destination, or we don’t really care where we’re going), and how long do we have to wait for it?

The thumbnail for this page

ELF relocations

The last article, Position-independent code, was a mess. But who could blame us? We looked at the world, and found it to be a chaotic and seemingly nonsensical place. So, in order to blend in, we had to let go of a little bit of sanity.

The time has come to reclaim it.

Short of faulty memory sticks, memory locations don’t magically turn from 0x0 into valid addresses. Someone is doing the turning, and we’re going to find out who, if it takes the rest of the series.

The thumbnail for this page

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
The thumbnail for this page

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?

The perils of ooc arguments

The ooc language is known to be friendly to C libraries, and we have a slew of them covered on GitHub, but one common hurdle is how to correctly declare extern functions.

Argument types

For an ooc function prototype, there are many types of arguments. You can go with regular variable declarations, like so:

something: func (a: Int, b: Int, c: String)

But in this case, a and b have the same type, so you can also use multi-declarations to shorten it a bit:

The thumbnail for this page

A static poppler build: the easy way

So! Now our asset processing pipeline is almost complete. But we’ve just traded dependencies against CLI tools, for dependencies against dynamic libraries:

$ ldd ./target/debug/pdftocairo linux-vdso.so.1 (0x00007ffd615be000) libpoppler-glib.so.8 => /lib64/libpoppler-glib.so.8 (0x00007f2ba1bb4000) libgobject-2.0.so.0 => /lib64/libgobject-2.0.so.0 (0x00007f2ba1b59000) libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f2ba1a1e000) libcairo.so.2 => /lib64/libcairo.so.2 (0x00007f2ba1902000) libcairo-gobject.so.2 => /lib64/libcairo-gobject.so.2 (0x00007f2ba18f6000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f2ba18dc000) libm.so.6 => /lib64/libm.so.6 (0x00007f2ba17fe000) libc.so.6 => /lib64/libc.so.6 (0x00007f2ba15f4000) /lib64/ld-linux-x86-64.so.2 (0x00007f2ba216c000) libpoppler.so.112 => /lib64/libpoppler.so.112 (0x00007f2ba1288000) libfreetype.so.6 => /lib64/libfreetype.so.6 (0x00007f2ba11bd000) libgio-2.0.so.0 => /lib64/libgio-2.0.so.0 (0x00007f2ba0fe4000) libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f2ba0dc5000) libffi.so.6 => /lib64/libffi.so.6 (0x00007f2ba0db8000) libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f2ba0d40000) libpixman-1.so.0 => /lib64/libpixman-1.so.0 (0x00007f2ba0c94000) libfontconfig.so.1 => /lib64/libfontconfig.so.1 (0x00007f2ba0c45000) libpng16.so.16 => /lib64/libpng16.so.16 (0x00007f2ba0c0c000) libxcb-shm.so.0 => /lib64/libxcb-shm.so.0 (0x00007f2ba0c07000) libxcb.so.1 => /lib64/libxcb.so.1 (0x00007f2ba0bda000) libxcb-render.so.0 => /lib64/libxcb-render.so.0 (0x00007f2ba0bca000) libXrender.so.1 => /lib64/libXrender.so.1 (0x00007f2ba0bbd000) libX11.so.6 => /lib64/libX11.so.6 (0x00007f2ba0a75000) libXext.so.6 => /lib64/libXext.so.6 (0x00007f2ba0a60000) libz.so.1 => /lib64/libz.so.1 (0x00007f2ba0a46000) libjpeg.so.62 => /lib64/libjpeg.so.62 (0x00007f2ba09c2000) libopenjp2.so.7 => /lib64/libopenjp2.so.7 (0x00007f2ba0968000) liblcms2.so.2 => /lib64/liblcms2.so.2 (0x00007f2ba0903000) libtiff.so.5 => /lib64/libtiff.so.5 (0x00007f2ba087c000) libsmime3.so => /lib64/libsmime3.so (0x00007f2ba0850000) libnss3.so => /lib64/libnss3.so (0x00007f2ba0712000) libplc4.so => /lib64/libplc4.so (0x00007f2ba0709000) libnspr4.so => /lib64/libnspr4.so (0x00007f2ba06c6000) libbz2.so.1 => /lib64/libbz2.so.1 (0x00007f2ba06b3000) libharfbuzz.so.0 => /lib64/libharfbuzz.so.0 (0x00007f2ba05dd000) libbrotlidec.so.1 => /lib64/libbrotlidec.so.1 (0x00007f2ba05cf000) libgmodule-2.0.so.0 => /lib64/libgmodule-2.0.so.0 (0x00007f2ba05c8000) libmount.so.1 => /lib64/libmount.so.1 (0x00007f2ba0581000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f2ba0556000) libxml2.so.2 => /lib64/libxml2.so.2 (0x00007f2ba03cd000) libXau.so.6 => /lib64/libXau.so.6 (0x00007f2ba03c7000) libwebp.so.7 => /lib64/libwebp.so.7 (0x00007f2ba0358000) libzstd.so.1 => /lib64/libzstd.so.1 (0x00007f2ba0260000) libjbig.so.2.1 => /lib64/libjbig.so.2.1 (0x00007f2ba0252000) libnssutil3.so => /lib64/libnssutil3.so (0x00007f2ba021f000) libplds4.so => /lib64/libplds4.so (0x00007f2ba021a000) libgraphite2.so.3 => /lib64/libgraphite2.so.3 (0x00007f2ba01f9000) libbrotlicommon.so.1 => /lib64/libbrotlicommon.so.1 (0x00007f2ba01d4000) libblkid.so.1 => /lib64/libblkid.so.1 (0x00007f2ba019c000) libpcre2-8.so.0 => /lib64/libpcre2-8.so.0 (0x00007f2ba0105000) liblzma.so.5 => /lib64/liblzma.so.5 (0x00007f2ba00d9000)