Blog

Showing Indentation, Spaces, Tabs (Invisibles) in Various Editors

Invisibles are the characters that are in your editor anyways, but they are usually not displayed with anything but empty space or simply completely invisible, like line breaks. Showing invisibles in Vi or Vim can easily be done by changing the vim config with the list and listchars properties. Other editors have config files or an easy to use UI like Atom or Visual Studio Code.

Continue reading “Showing Indentation, Spaces, Tabs (Invisibles) in Various Editors”

Raspberry Pi (4) Kiosk / Wall Display / Dashboard

This post is about setting up a display with a Raspberry PI or similar computer using Linux, potentially raspbian / n00bs on an sd card and a screen. The Raspberry Pi 4 has some respectable specs is quiet, displays up to 4k and has Wi-Fi which makes it a pretty great dashboard display source.

Continue reading “Raspberry Pi (4) Kiosk / Wall Display / Dashboard”

How to quit vim / nano / any text editor on Linux

How do I quit vim?!

Has become a running gag of the computer nerd community for a few decades now, but recently I was asked by a fellow developer how to quit vim. Colour me surprised when what I saw in the terminal was not vim, but nano. After a few days of procrastination and consideration I thought it wouldn’t be too much to write a post about how to quit different text editors.

Continue reading “How to quit vim / nano / any text editor on Linux”

Codefund: Ethical Google Adsense Alternative?

In this article I’ll have a look at Codefund, which is an online advertising platform specifically targeted at the tech sector. So if you’re looking to monetize your tech blog, the documentation of you open source project or similar, this might be a possibly solution for you.

Continue reading “Codefund: Ethical Google Adsense Alternative?”

Music Monday: Sabaton, Combichrist, RAMMSTEIN, Storm Seeker

This Music Monday is going to be a bit different, because it’s not about one artist or band, but a few different ones (because with the old model, I’ll never get through them all).

Continue reading “Music Monday: Sabaton, Combichrist, RAMMSTEIN, Storm Seeker”

Cookies, sessionStorage, localStorage. What’s the difference?!

This post is about different storage possibilities in your browser. There are cookies, and different kinds of storage that can be accessed through JavaScript APIs in your client side code. They’re used for authentication, tracking tools like Google Analytics and a lot of other stuff, so let’s have a look at how they work!

Continue reading “Cookies, sessionStorage, localStorage. What’s the difference?!”

Web Components 101: Hello World

Web Components are a way to encapsulate functionality into little self-contained parts that can be reused and adapted like you’re used to from frontend libraries like React, Vue, Angular or Ember. The special thing about Web components is that they work straight in your browser.

When it comes to support, a lot of features are supported in all major browsers, as can bee checked out at caniuse.com.

As you might have seen, web components usually are understood as several sub-parts, mostly:

Continue reading “Web Components 101: Hello World”

Unit Tests with Rust Tutorial 101

Writing unit tests is heavily integrated into rust without additional dependencies or external test runners. You can write unit tests inside the file that has the testable code or use a separate tests directory, let’s see how we do that.

You don’t need to have any prior rust knowledge, but you will have to have rust installed, which most easily is done by using rustup.

Writing Your First Test

When creating a rust project with cargo new and we’ll need a function that takes arguments and returns something, so let’s go for a simple sum function in main.rs:

fn sum(a: i32, b: i32) -> i32 {
    return a + b;
}

fn main(){
    println!("12 + 1 is {}", sum(12,1));
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn sum_test() {
        assert_eq!(345+5, sum(345, 5));
    }
}

Now for the interesting parts in the bottom of the file

  • #[cfg(test)] <- the test section attribute (see conditional compilation)
  • #[test] <- the test attribute for the individual test
  • assert_eq! macro to compare the two values

This is the simplest way to implement a unit test in rust, the next step is to look at how to move your functions and tests into another separate file.

Running cargo test should output something like:

    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running target/debug/deps/rust_test_101-e2cf395340fbef91

running 1 test
test tests::sum_test ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Adding the following has the correct types, but it would cause the return value to be larger than i32 allows:

#[test]
#[should_panic]
fn greater_than_i32() {
    sum(2147483647,1); // this would be bigger than i32 allows
}

By using #[should_panic] we tell the test run to expect the following function to fail. This catches errors that usually crop up with:

thread 'main' panicked at 'attempt to add with overflow', src/main.rs:2:12

Now this is the easiest possible way to get started with writing tests in Rust, let me know if you want to know more in future posts! Don’t forget to check out the Rust Book Chapter on Testing as well.