205 results for "":

Binding C APIs with variable-length structs and UTF-16

Okay, I lied.

I’m deciding - right this instant - that using wmic is cheating too. Oh, it was fair game when we were learning about Windows, but we’re past that now.

We know there’s IPv4 routing tables, and we know network interfaces have indices (yes, they do change when you disable/enable one, so ill-timed configuration changes may make our program blow up).

Program in C (Parody song)

Once upon a time, @Cinememer wrote some alternative lyrics to “Under The Sea”. I couldn’t resist singing them!

I unfortunately lost the audio files for this. Oh well.

Cut for time

This series has to end somewhere, so let’s end it here!

However, here is a list of some things I’d like to come back to:

Bundling & TypeScript

Using a bundler like Parcel so I can write some of the client-side logic in TypeScript, have it take care of building the SCSS, etc.

I do that to great effect in another project of mine and I’d like to show you how I did it!

Huffman 101

Let’s play a game: your objective is to guess a word, but you can only ask yes or no questions. You should also aim to ask as few questions as possible.

You might have played a variant of this game before, guessing famous actors or musicians. You’d usually ask questions like “Are they alive?”, or “Have they won an Oscar”? And that would allow you to narrow down the possibilities, until you finally resort to a list of direct guesses (“Is it Amy Adams?”) or simply give up.

A no_std Rust binary

In Part 11, we spent some time clarifying mechanisms we had previously glossed over: how variables and functions from other ELF objects were accessed at runtime.

We saw that doing so “proper” required the cooperation of the compiler, the assembler, the linker, and the dynamic loader. We also learned that the mechanism for functions was actually quite complicated! And sorta clever!

Printing ASCII cats to the terminal

Now that our development environment is all set up, let’s make something useful!

Creating the catscii crate

From a VS Code window connected to our VM (as we just set up), let’s make a new Rust project:

amos@miles:~$ cargo new catscii Created binary (application) `catscii` package

And open it in a new VSCode window:

amos@miles:~$ code catscii

Even though we’re running this “code” command in the VM guest, VSCode set up enough plumbing that it communicates back to the host, telling it to open another VSCode window, connected to the same SSH remote, in the right folder.

The builder pattern, and a macro that keeps FFI code DRY

Our ping API is simple, but it’s also very limited:

pub fn ping(dest: ipv4::Addr) -> Result<(), String> // called as: ping(ipv4::Addr([8, 8, 8, 8])).unwrap();

It doesn’t allow specifying the TTL (time to live) of packets, it doesn’t allow specifying the timeout, it doesn’t let one specify the data to send along, and it doesn’t give us any kind of information on the reply.

From Inkscape to poppler

What’s next? Well… poppler is the library Inkscape uses to import PDFs.

fortris

Cool bear Cool Bear's Hot Tip

Yes, the name comes from Futurama.

Turns out, poppler comes with a bunch of CLI tools, including pdftocairo!

Amos

Halfway through this article, I realized the “regular weight” on my system was in fact Iosevka SS01 (Andale Mono Style) (see Releases), but the “bold weight” was the default Iosevka.

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”

Recursive iterators in Rust

I’ve been looking for this blog post everywhere, but it doesn’t exist, so I guess it’s my turn to write about Some Fun with Rust.

The task at hand

Let’s say you have a recursive, acyclic data structure, like so:

struct Node { values: Vec<i32>, children: Vec<Node>, }

This allows you to represent a tree-like structure:

[1, 2, 3] /\ / \ / \ / \ / \ [4, 5] [6, 7]