Scott O'Brien

Projects, Ramblings and Resources of my (online) life


2022-04-27 00:00:00 +0000 UTC

Why learn Rust?

In Network Engineering at Facebook Meta, we’ve been going through an interesting transformation in which we’re starting to be discouraged to write new services in Python, and, instead start writing more in Rust (and sorry Golang, of which we’ve already got a bit written in.

I’ve always said that I’m not overly a smart person (though am stubborn enough to solve most problems), and don’t expect to be able to pick it up quickly, I decided to start learning by challenge tasks, do as much as I can in it, and document some here.

For my challenges, I’m going to use both Project Euler and compare my solutions in Python and Rust. Python because it’s my most comfortable language.


Multiples of 3 or 5

This one threw me slightly. Nice and easy to play with iterators, but I don’t get why I needed to give it a type in rust. I’d have thought the range might have been smart enough to infer the type?


print(sum(x for x in list(range(1,1000)) if x % 3 == 0 or x % 5 == 0 ))


fn main() {
    let sum: i32 = (1..1000).filter(|x| x % 3 == 0 || x % 5 == 0).sum();
        println!("{}", sum);

Adjacent Nodes

This one is worth writing out. This problem effectively has a 2D array, and asks us to lookup if the value in a given position is a 0, or 1. It should be super simple, but I spent many hours on learning about ways of going about doing this. Some observations


Rust: This one got me very, very confused. Some observations:

  • This was my first attempt
    • I couldn’t figure out how to pass the arrays of variable size through to the is_adjacent function, so I instead used Vectors. Not sure if this is accepted practice considering I probably don’t need the overhead of ever adding/removing items in the constant matrix here
    • The code did not use any errors, but avoided run-time bound checking panics by making good use of the get call.
  • This was my second attempt.
    • This is interesting, that we have an Optional return type, and force the users to read the docs to know what the return behavior will be (I guess no different to returning errors and docs specifying what errors can be returned)
    • Made use of the ? operator to be able to filter errors right back up to a Null return type.

ESPChess NewGame Bug

2022-04-05 00:00:00 +0000 UTC

Ordering is a little off here, but I wanted to writeup about a bug I’m seeing in the ESPChess project (post to come) and how I intend to fix it.

The chessboard uses AWS IoT Shadow Service (MQTT accessed key-value store) to keep track of your and your opponents chess board state. It has a sequence number that’s incremeneted to flag when we should update our current state to match our opponents.

Once a game is finished, it shows who won the game. Once all the pieces are back in their starting position, it attempts to restart the game, and flip the black and white players around. The problem is, when testing this out with my father, that it’s not all that user friendly, and it’s a bit finicky. When a game is finished, the colors show the delta with the old game, and not a new game. I think the new logic should be:

  • We store lastGameState
  • We store lastGamePreviousMoveState
  • If the sequence number is 0, and the current board state matches the lastGameState or lastGamePreviousMoveState, then show the winner or delta, otherwise show the delta with the current (presumably new game) board state.
  • When a board finishes the game, it should update the lastGameState, lastGamePreviousMoveState to the current winning move state. gameState and gamePreviousMoveState should be reset to a new starting position.
  • In the event of the opponents sequence number being 0, and ours not, update our state to match our opponents (with the isWhite value flipped)

NFT Hydroponic System

2022-01-02 00:00:00 +0000 UTC

As my hydroponic experiemnt has shown success, I wanted to scale this up. My plan is to build an NFT hydroponic system for the yard, and dutch bucket for tomatoes.

From my light study I found the fence and some areas that may make some good light.

I found that describes NFT Hydroponics is 4-6 GPH required for my pump. I’m going to start with one trough, but plan on scaling this up to 3 if it works, so will require 18GPH of total flow. 7 feet of height is required if I want to mount this on the top of the fence.

Build Guide

Note: This is a work in progress. Will update as it gets built!

Hydroponic Kratky Lettuce Attempts

2021-12-05 11:01:04 -0800 -0800

This year i’ve decided to start playing with Hydroponics as a hobby. I’ve been interested in starting with the Kratky Method of gardening. The idea is to grow lettuce in mason jars and see how growing without soil does. I’ve previously enjoyed growing my own alfalfa micro-greens, so this is the next obvious step.

Attempt #1

These didn’t go so good. I had planted some seedlings in Rockwool, and left them in a container out in the sun to act as a mini-greenhouse. In the SF Bay area getting towards winter, I feel it may have been too cold, and most of my seedlings ended up dying off. The mason jar didn’t do so well once it was planted either. ~6 weeks in I’d call my first attempt a failure.

Attempt 2

  • 22nd November: Planted seeds in Rockwool
  • ~29th November: Started moving to a half-nutrient watering solution
  • 5th December (+13 days): Moved to mason jars

I decided to try and move indoors. I got a 150 Watt LED bulb (5000K) to provide the light, and turned my old proofing box to a simple 9 hour a day timer. I find this is a good time of a year for indoor growing as the temperature with the grow light on is between 14c and 23c of a day. The ideal temperature for growing is 13-18c, so I’m curious to see how they go indoors in the warmer climate.

I’m using this guide for measuring the lettuce levels:

  • PH: 5.5-6.5
  • EC: 0.8-1.2

note: Work in progress. Will update once plants have had more of a chance to grow.