Skip to content

Instantly share code, notes, and snippets.

View Integralist's full-sized avatar
🎯
Making an impact

Mark McDonnell Integralist

🎯
Making an impact
View GitHub Profile
@Integralist
Integralist / .editorconfig
Created May 8, 2024 13:44
[Example Editor Config] #editorconfig
root = true
[*]
indent_size = 2
charset = utf-8
end_of_line = lf
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true
@Integralist
Integralist / aspect_ratio.py
Last active May 7, 2024 05:59
[Calculate Aspect Ratio] #aspect #ratio #python
def calculate_aspect(width: int, height: int) -> str:
def gcd(a, b):
"""The GCD (greatest common divisor) is the highest number that evenly divides both width and height."""
return a if b == 0 else gcd(b, a % b)
r = gcd(width, height)
x = int(width / r)
y = int(height / r)
return f"{x}:{y}"

Install the netcat nc command with Homebrew (otherwise Mac OS X version is really old and the interface is different):

brew install netcat

Use netcat to listen for incoming TCP connections on port 3000:

nc -l -p 3000
@Integralist
Integralist / Python3 HTTP Server.py
Last active May 2, 2024 12:35
Python3 HTTP Server.py
import time
from http.server import BaseHTTPRequestHandler, HTTPServer
HOST_NAME = 'localhost'
PORT_NUMBER = 9000
class MyHandler(BaseHTTPRequestHandler):
def do_HEAD(self):
self.send_response(200)
@Integralist
Integralist / SLI, SLO, SLA.md
Last active April 30, 2024 03:07
[SLI, SLO, SLA] #SLI #SLO #SLA #Process #Service

SLI, SLO, SLA ?

When building a service, we have a responsibility to define some baseline agreements as to the service’s expected uptime and performance. This document focuses on the various terminology that we use to define these values.

  • Service Level Indicator (SLI)
    What the service owner has chosen to measure progress towards their goal.

  • Service Level Objective (SLO)
    What the service owner’s goal is for the given indicator.

@Integralist
Integralist / Different Testing Styles.md
Created April 29, 2024 09:03
[Different Testing Styles] #tests #terminology #system

Unit test

Specify and test one point of the contract of single method of a class. This should have a very narrow and well defined scope. Complex dependencies and interactions to the outside world are stubbed or mocked.

Integration test

Test the correct inter-operation of multiple subsystems. There is whole spectrum there, from testing integration between two classes, to testing integration with the production environment.

Acceptance test

@Integralist
Integralist / rules for good testing.md
Last active April 24, 2024 15:09
Sandi Metz advice for writing tests

Rules for good testing

Look at the following image...

...it shows an object being tested.

You can't see inside the object. All you can do is send it messages. This is an important point to make because we should be "testing the interface, and NOT the implementation" - doing so will allow us to change the implementation without causing our tests to break.

@Integralist
Integralist / Caution with Bash when copying Files and Directories.bash
Last active April 24, 2024 05:48
[Copying Files and Directories] #bash #cp #copy #files #directories
# copy src directory into the destination directory
# i.e. you'll end up with compute/src/...
cp -r src ~/Code/rust/compute/
# copy the 'files' from the src directory into the destination directory
# i.e. you'll end up with compute/...
#
# NOTICE the subtle difference! a trailing slash on src/ will
# copy the files within that directory rather than the directory as a whole.
cp -r src/ ~/Code/rust/compute/
@Integralist
Integralist / JavaScript Execution.md
Created December 27, 2011 23:00
Execution context within JavaScript (Variable/Activation Object) shortened from @kangax's post on 'Understanding delete'
@Integralist
Integralist / README.md
Last active April 17, 2024 08:23
[golang custom http client] #go #golang #http #client #timeouts #dns #resolver