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 / 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
@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

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.

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()
const fastify = require('fastify')
const app = fastify()
const db = {
requests: [
{
id: 1,
requester: "David",
date: "2020-10-12",
note: "",
@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 {}
@fxdave
fxdave / main.rs
Last active January 4, 2021 01:23
rust react style native gui toolkit concept
struct Styles {
padding: f64,
color: Color,
font_size: f64,
}
impl Styles {
fn with_padding(self, value: f64) -> Styles {
self.padding = value;
self
@fxdave
fxdave / main.rs
Last active April 13, 2020 22:17
Bulky Cached Rust File Repository
mod seri {
pub trait Deserialize {
fn deserialize(atoms: Vec<String>) -> Option<Self>
where
Self: Sized;
}
}
mod db {
use super::seri::Deserialize;
@fxdave
fxdave / main.rs
Created April 13, 2020 16:37
Simple Rust File repository
use std::error::Error;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
mod seri {
pub trait Deserialize {
fn deserialize(atoms: Vec<String>) -> Option<Self>
where
Self: Sized;
@fxdave
fxdave / main.rs
Created December 29, 2019 16:09
example code for XCB in rust
extern crate xcb;
fn main() {
let (conn, screen_num) = xcb::Connection::connect(None).unwrap();
let screen = conn.get_setup().roots().nth(screen_num as usize).unwrap();
let foreground = conn.generate_id();
xcb::create_gc(
&conn,