Stop using CSS classes

Think about these things first before adding a CSS class to your HTML element.

Should I be using this HTML tag or is there a more appropriate element?

Read through the list of HTML elements and see if a closer match exists. You should have at least one <main> tag on your page, and probably at least one <header> tag too. Almost every website should have at least one <nav> and you may want to add some <article> or <section> tags.

Continue

My Bare Metal RPi journey

I bought a Raspberry Pi 3 B+ a few years ago about the time I started learning Rust which was also about when I took OS dev. I wanted to learn OS development and I’d heard about CS140e so I thought it would be relatively easy. And it has been relatively easy when compared to interchanging the OS on my laptop which is the alternative I was considering. The Raspberry Pi has a lot of tutorials and examples, it’s hard to brick, it can netboot, it has user and kernel mode, and it has GPIO that would be fun to play with.

Continue

The Most Cursed JavaScript

There was an old trick used by Angular and a few other libraries of using a function's source code (which you can get using .toString()) to get its argument names. Promisify-node used this technique to find arguments called callback or cb. Angular uses it for dependency injection, though there are other better ways of doing that.

Continue

How to parse HTML with Regular Expressions

Sample of what we'll be building

I’ll be using JavaScript here. With it we can write this in <100 lines of code.

Harness

We’ll start by laying out our code. I’ll be using closures, but you could — and my first version did — use a class instead. We’ll need a parse_html function, inside we’ll put a helper function called pull and a parse_content function which we’ll fill in later.

If you’d like to follow along, the finished code is here: regex-html

Continue

How to Instantiate HTML Template Elements

I'm excited about template elements. There's no specified way of instantiating them, so let's talk about where they come from, why we use them, and how to instantiate them.

Continue

Built-In and Custom Traits in JavaScript

The Problem

Polymorphism is important in any language and while it is very easy to write polymorphic code in JavaScript, it is relatively hard to manage that code. Without explicit types you must either assume the structure of an object, or explicitly test its structure before using any functionality. Explicitly testing slows down your code, while making unsound assumptions usually results in bugs. This might sound like a trade off, but it’s just another problem for which fast and safe solutions exist.

Continue