Skip to content

Instantly share code, notes, and snippets.

@wzulfikar
Last active Nov 25, 2022
Embed
What would you like to do?
Logs
flowchart TD
  Notes -.-> Problem-based
  Notes -.-> Observations
  Notes --You are here--> Logs[<strong>Logs</strong>]
  Notes -.-> Challenges
  Notes -.-> Electronics

  click Problem-based "https://gist.github.com/wzulfikar/ba2f58d7aeeb3cf53743316f96f91594"
  click Observations "https://gist.github.com/wzulfikar/2cff9bcd64ba5f15296e0b57ff402f79"
  click Logs "https://gist.github.com/wzulfikar/5ea5779d7f2ea0e27809e94e7904f93d"
  click Challenges "https://gist.github.com/wzulfikar/7d5e9426d1c7efc3ceeabb29adb2f4fd"
  click Electronics "https://gist.github.com/wzulfikar/16c3b5f10b8f28d8b0e325d03c948d1c"

Problem-based · Observations · Logs · Challenges · Electronics

@wzulfikar
Copy link
Author

wzulfikar commented Nov 3, 2022

Log #1 · Learning Rust 🦀

In 2018 I started learning Go and built some systems with it (GraphQL backend, Telegram bot). Around that time, I got to know Rust and my first impression was the slower compilation time and steeper learning curve (borrow checker, lifetimes). Borrow checker is what made me interested in Rust at first. However, I never actually dig deeper to understand how and why it works.

Now, with so many tools built with Rust (swc, ripgrep), learning Rust is even more interesting because I get to see it in the tools that I use every day.

My plan is to get thru the new concepts first and then walk up to higher level understanding. Here's the resources that I find helpful:

  • YouTube channel: Code to the Moon.
    It helps me understand borrow checker, containers, lifetimes, and other things that I haven't used before. The pace is fits me well and the sample codes are easy to understand.

  • YouTube channel: No Boilerplate
    Compared to Code to the Moon, No Boilerplate talks about Rust concept at a higher level. It's really nice because it helps me consolidate the details I learned from Code to the Moon. It lets me see the bigger picture. I basically watched all the videos in Rust Talks playlist.

  • Udemy course (paid): Ultimate Rust Crash Course
    The YouTube videos helped me far with understanding the fundamentals but I wanted to do something from start to end so I can crystalize my understanding and I find this course helpful. It's not free but in hindsight, it's worth it. If you stumbled upon Udemy sales promotion, you could get it for ~$9 which is very cheap compared to what you get.

    The course has a Github repo where you'll work thru the exercises. I did the exercises, and it's actually helpful. If you just want to do the exercises, you don't need to buy the course. There's also Ultimate Rust 2: Intermediate Concepts which is a continuation of this course. I love how Nathan Stocks teach the course and so I got it too.

  • Book: The Rust Programming Language

    This was actually my first resource but I couldn't really grasp what's in there, likely because I didn't have enough fundamentals to understand it. But now, things makes more sense and it's sometimes easier to refer to a book instead of video.

So that's it. It's been 3 weeks since I started the learning, roughly 1 hour every other day. It's not much, but it's not nothing. The goal is to be comfortable working in Rust codebase. The structure, the test, the development process. I think I can get there. Let's see :)

▲▼▲

Note to self: took me 1 hour to write this log.

@wzulfikar
Copy link
Author

wzulfikar commented Nov 13, 2022

Log #2 · facegrep – my first Rust program 🚀

Last week (Nov 4, 2022) I wrote my first Rust program, facegrep. It's a command line program that detects a face from an image:

  1. Let's use the test image at assets/test/scientists.jpg
  2. Pass the test image to the command line: facegrep assets/test/scientists.jpg
  3. The command found 29 faces and created a new image at assets/test/scientists.jpg-facegrep.png
  4. Let's see the image and we'll see the red squares on each face
  5. Now, let's use the command to output json instead of image: facegrep assets/test/scientists.jpg --json | jq
  6. The command will show the array of face data (bbox and score) in json format
Screen.Recording.2022-11-13.at.11.42.59.mov

▲▼▲

Here's how I got the idea.

I was checking twitter and saw a tweet from @levelsio:

and I thought, "maybe I can do it in Rust? Maybe someone has done the algorithm and I only need to port it to Rust?". After a quick search, I found about Rustface which fits the bill: it detects face, doesn't require GPU, no external dependencies (eg. dlib, opencv). In fact, it's a port of C++ library Seetaface which is a face recognition engine.

I started digging Rustface codebase and felt like I'am profiting from my learning: I know where to start my digging (I started from src/lib.rs), how the type system works, and most importantly I wasn't afraid of looking at the codes. The codebase was modular so I know it's not going to be heavy work to just wrap the library in a command line.

I used examples/image_demo.rs as starting point. It detects faces from the test image and draw red boxes on each face, so I only need to:

  1. Change the test image to use the image from command line argument
  2. Add option to output json

You'll see the final code in main.rs file of the facegrep repo. As you may have noticed, I didn't actually do a lot of work. It was mostly reorganizing the existing code to fit my need. Nevertheless, it was a good exercise to practice what I learnt.

  • Do I want to learn even more Rust after this exercise?
    Yes, definitely. I was able to pick random repository (ie. Rustface) and figure out what it does. Rust codebase is no longer something scary to look at.
  • Should I continue learning from the same resource, with the same style?
    Yes, I should. From this exercise, I've seen that the knowledge I gained from the resources (see Log #1) has materialized easily in real use case.

That's it! I think I'm on the right path. Looking forward to learning more Rust 🦀

▲▼▲

Note to self: took me 45 min to write this log.

@wzulfikar
Copy link
Author

wzulfikar commented Nov 25, 2022

Log #3 · Books I want to read 📚

About design:

About software:

▲▼▲

Might be good but still unsure:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment