Skip to content

Instantly share code, notes, and snippets.

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

Patrick Kalkman PatrickKalkman

🏠
Working from home
View GitHub Profile
@PatrickKalkman
PatrickKalkman / HealthController.cs
Created June 20, 2021 17:46
Adding logging to the health check controller
[ApiController]
[Route("[controller]")]
public class HealthCheckController : ControllerBase
{
private readonly ILogger<HealthCheckController> _logger;
public HealthCheckController(ILogger<HealthCheckController> logger)
{
_logger = logger;
}
@PatrickKalkman
PatrickKalkman / healthcheckcontroller.cs
Created June 20, 2021 16:15
Controller that receives the health check request
[ApiController]
[Route("[controller]")]
public class HealthCheckController : ControllerBase
{
private readonly ILogger<HealthCheckController> _logger;
public HealthCheckController(ILogger<HealthCheckController> logger)
{
_logger = logger;
}
@PatrickKalkman
PatrickKalkman / Dockerfile
Created June 20, 2021 16:09
A dockerfile that contains a health check
# We use the alpine as base image
FROM mcr.microsoft.com/dotnet/aspnet:5.0-alpine-amd64
# Perform the health check call via curl
HEALTHCHECK --interval=5s --timeout=3s CMD curl --fail http://localhost/healthcheck || exit 1
RUN apk --update --no-cache add curl
# Create a group and usermcr.microsoft.com/dotnet/runtime
RUN addgroup --gid 1000 -S app && adduser --uid 1000 -S app -G app
@PatrickKalkman
PatrickKalkman / program.cs
Created June 20, 2021 13:20
Handling SIGINT & SIGTERM
class Program
{
static async Task Main(string[] args)
{
AppDomain.CurrentDomain.ProcessExit += (_, _) =>
{
Console.WriteLine("Received SIGTERM");
};
Console.CancelKeyPress += (_, _) =>
@PatrickKalkman
PatrickKalkman / Dockerfile
Created June 20, 2021 07:55
Microsoft .NET Non Root Docker image
# We use the alpine as base image
FROM mcr.microsoft.com/dotnet/runtime:5.0-alpine-amd64
# Create a group and user
RUN addgroup --gid 1000 -S app && adduser --uid 1000 -S app -G app
# Create the work dir and set permissions as WORKDIR set the permissions as root
RUN mkdir /home/app/net && chown -R app:app /home/app/net
WORKDIR /home/app/net
@PatrickKalkman
PatrickKalkman / calculate_rotation.py
Created June 13, 2021 11:57
Calculcate the rotation of the enemy space ship
def calculate_rotation(self, previous_point, current_point):
dx = current_point.xpos - previous_point.xpos
dy = current_point.ypos - previous_point.ypos
return math.degrees(math.atan2(dx, dy)) + 180
@PatrickKalkman
PatrickKalkman / shoot.py
Created June 13, 2021 10:02
The enemy space ship shoots a rocket towards the player
def enemy_shoots(self):
nr_of_enemies = len(self.all_enemies)
if nr_of_enemies > 0:
enemy_index = random.randint(0, nr_of_enemies - 1)
start_rocket = None
for index, enemy in enumerate(self.all_enemies):
if index == enemy_index:
start_rocket = enemy.rect.center
if start_rocket[1] < 400:
@PatrickKalkman
PatrickKalkman / StarField.py
Created June 13, 2021 06:57
The background star field
class StarField():
def __init__(self):
self.star_field_slow = self.create_stars(50)
self.star_field_medium = self.create_stars(35)
self.star_field_fast = self.create_stars(30)
def create_stars(self, number_of_stars):
stars = []
for _ in range(number_of_stars):
star_loc_x = random.randrange(0, constants.SCREEN_WIDTH)
@PatrickKalkman
PatrickKalkman / controlhandlermover.py
Created June 13, 2021 06:10
class to move control handles and points
class ControlHandlerMover():
def __init__(self,
control_point_quartet_collection: ControlPointQuartetCollection,
path_point_selector: PathPointSelector):
self.control_point_quartet_collection = control_point_quartet_collection
self.path_point_selector = path_point_selector
def move_control_handler(self, control_point_handler: ControlPointHandler, x: int, y: int):
dx = self.control_point_quartet_collection.get_control_point(control_point_handler).x - x
dy = self.control_point_quartet_collection.get_control_point(control_point_handler).y - y
@PatrickKalkman
PatrickKalkman / pathpointcalculator.py
Created June 12, 2021 20:20
Calculating the points of the bezier curve
class PathPointCalculator():
@staticmethod
def calculate_path_point(control_point_quartet: ControlPointQuartet,
time_to_calculate: float):
time: float = time_to_calculate - int(time_to_calculate)
cx: float = 3.0 * (control_point_quartet.get_point(1).x -
control_point_quartet.get_point(0).x)
cy: float = 3.0 * (control_point_quartet.get_point(1).y -