Skip to content

Instantly share code, notes, and snippets.

View fxdave's full-sized avatar
🏠
Working from home

David Judge fxdave

🏠
Working from home
View GitHub Profile
@fxdave
fxdave / borrow.rs
Created October 26, 2021 17:42
Webinar code examples
struct Foo {
numbers: Vec<i32>,
}
struct Bar;
impl Bar {
fn new(foo: &mut Foo) -> Self {
foo.numbers = vec![];
Self {}
const fastify = require('fastify')
const app = fastify()
const db = {
requests: [
{
id: 1,
requester: "David",
date: "2020-10-12",
note: "",

Base concept

For small projects, I usually instantiate every service (Dependencies) in one file, and when everything is up and running, we can start the server, and we can access everything. Like in this example (a python API from a high voltage wire designer app):

# Dependencies

wind_effect_calculator = WindEffectCalculator()
wind_pressure_calculator = WindPressureCalculator()
wire_density_calculator = WireDensityCalculator(CriticalStanchionDistanceCalculator())
wire_tension_calculator = WireTensionCalculator()

In theory, we use dev containers, because, we don't have the same environment locally. If one would develop NodeJs, they shouln't have to install node on their main machine that they use as a daily driver. They only need the image, that has these tools. And the best way to define images is using docker.

Dockerfile is for building an image. Containerd is for starting a process inside one of these images. An isolated process is called as "container". (you can use linux utilities for this, docker is optional) However, docker makes it easy to mount the image and make the image as root of the container.

Imagine that you have a "node:latest" image. You want to use npm for like checking the version. You run this: docker-compose run node npm --version It's clear that you don't need npm install to do this.

@fxdave
fxdave / Makefile
Last active November 23, 2022 21:12
cache commands by file in Makefile
# Cached "sayhi"
sayhi_key = $(shell sha1sum deleteme.md)
stored_sayhi_key = $(shell cat .sayhi_key)
sayhi:
ifeq ($(sayhi_key), $(stored_sayhi_key))
@echo "I've already said hi"
else
@echo "Hi"
@echo "$(sayhi_key)" > .sayhi_key
endif
@fxdave
fxdave / for_oop_haters.md
Last active February 8, 2023 20:42
For OOP Haters

It depends on what do you mean by OOP. If you want to mimic real life objects (the definition that we were told) that's not gonna work well. If it's about using objects that are communicating with each other through function calls, then it's not wrong at all.

Secondly, respecting functional paradigms, you might want to avoid state, mutation and side effect for classes as well. If you do this, you get classes that are only groups of functions, however, with a huge difference: You can have shared dependencies. So you can loosely couple software units. It has 2 really precious adventages:

  • easy unit testing
  • code generalization capability