Archive
Iosevka: a very nice font for coding
I found a very nice font for coding, called Iosevka ( https://github.com/be5invis/Iosevka ). Under Manjaro, I installed the following packages: ttf-iosevka-fixed and ttf-iosevka-nerd .
When you want to specify these fonts, for instance in VS Code, they are called “Iosevka Fixed” and “Iosevka Nerd Font”. The nerd version replaces mathematical signs with their ligatures, e.g. “>=” becomes “≥”. I hated it, so I use the “fixed” version, which behaves normally.
VS Code settings
I have this line in my settings.json:
"editor.fontFamily": "Iosevka Fixed, Hack, Consolas, 'Courier New', monospace",
[rust] fast hashmap
Problem
In Rust, the stdlib’s HashMap is quite slow. It’s secure, resistant against DOS attacks, but slow. If I write a tool that I want to use myself, it doesn’t have to be cryptographically secure. I want it to be fast.
Solution
I tried several alternatives and fxhash proved to be the fastest. I compared the stdlib, hashbrown, ahash and fxhash, and fxhash proved to be the fastest.
Usage
In Cargo.toml:
[dependencies] fxhash = "0.2"
In your code:
use fxhash::FxHashMap as HashMap; // after these renames, it can be used
use fxhash::FxHashSet as HashSet; // as a drop-in replacement
fn main() {
let mut map: HashMap = HashMap::default(); // !!! it's called ::default(), not ::new()
map.insert(1, "one");
map.insert(2, "two");
println!("{:?}", map); // {2: "two", 1: "one"}
println!("{}", map.get(&1).unwrap()); // one
}
Credits
I asked on GitHub how to have a fast hashmap in Rust, and the author of hashbrown directed me to these crates. As Amanieu explained, FxHashMap and AHashMap are aliases of the stdlib’s hashmap with custom hashers.
[Nim] A URL shortener command-line app.
This afternoon I wrote a URL shortener command-line application in Nim. It uses the bit.ly URL shortener service.
You can find the project here: https://github.com/jabbalaci/UrlShortener .
Hackr.io: Share and discover the best programming tutorials and courses online
Here you can find a nice collection of programming tutorials.
black magic: 0x5f3759df
The number 0x5f3759df is a magic constant that can be used to calculate the inverse square root of a number very efficiently. See this post for a detailed explanation. Now if you come across this number (which can happen anywhere, anytime), you will say “aha, I know that one”.
Programming, Motherfucker!
“We are a community of motherfucking programmers who have been humiliated by software development methodologies for years. We are tired of XP, Scrum, Kanban, Waterfall, Software Craftsmanship (aka XP-Lite) and anything else getting in the way of…Programming, Motherfucker.”
List of freely available programming books
brute force
“When in doubt, use brute force.” — Ken Thompson
Eh :)
You must be logged in to post a comment.