Skip to content

Instantly share code, notes, and snippets.

View rstropek's full-sized avatar

Rainer Stropek rstropek

View GitHub Profile
@rstropek
rstropek / 01-old-style.cs
Last active November 30, 2020 11:37
C# Records
var heroes = new Hero[] {
new("Homelander", "DC", true),
new("Jessica Jones", "Marvel", false),
};
class Hero {
public Hero(string name, string universe, bool canFly) =>
(Name, Universe, CanFly) = (name, universe, canFly);
public string Name { get; }
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Threading;
using System.Threading.Tasks;
var host = new HostBuilder()
.ConfigureServices((hostContext, services) => services.AddHostedService<ShutdownService>())
.UseConsoleLifetime()
.Build();
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -o out
using System;
using System.Threading.Tasks;
var tcs = new TaskCompletionSource();
var sigintReceived = false;
Console.WriteLine("Waiting for SIGINT/SIGTERM");
Console.CancelKeyPress += (_, ea) =>
{
@rstropek
rstropek / Program.cs
Last active August 19, 2020 13:47
Use case for C# 9's attributes on local functions
using System.Security.Claims;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@rstropek
rstropek / math.js
Created October 8, 2018 04:54
Code Snippet for Course "GitHub for Computer Science Classes"
exports.add = function (x, y) {
return x + y;
}
exports.sub = function (x, y) {
return x - y;
}
exports.sumOfPositiveNumbers = function (upperLimitInclusive) {
let result = 0;