Skip to content

Instantly share code, notes, and snippets.

View tormodfj's full-sized avatar
💡
Inventing code

Tormod Fjeldskår tormodfj

💡
Inventing code
View GitHub Profile
@tormodfj
tormodfj / AsyncLazy.cs
Last active October 11, 2021 10:48
AsyncLazy<T>
/// <summary>
/// Async edition of <see cref="Lazy{T}"/>.
/// </summary>
/// <typeparam name="T">The type of the lazily initialized value</typeparam>
public class AsyncLazy<T> : Lazy<Task<T>>
{
public AsyncLazy(Func<T> valueFactory)
: base(() => Task.Run(valueFactory)) { }
public AsyncLazy(Func<Task<T>> asyncValueFactory)
# This will allow the job to only execute for Pull Request builds
condition: eq(variables['Build.Reason'], 'PullRequest')
steps:
- task: UseDotNet@2
displayName: 'Use .Net Core runtime 3.1.x'
inputs:
packageType: runtime
version: 3.1.x
using System;
using System.Text;
public class Program
{
public static void Main()
{
var password = "SuperSecretLongPassword";
var bytes = Encoding.UTF8.GetBytes(password);
var base64 = Convert.ToBase64String(bytes);
@tormodfj
tormodfj / Get-WeatherForecast.ps1
Last active October 29, 2023 13:38
Scripts from my PowerShell talk
function Get-WeatherForecast {
<#
.SYNOPSIS
Gets the weather forecast for a location of choice.
.DESCRIPTION
Displays the weather forecast for a location of choice, directly in
the terminal. Powered by wttr.in.
.NOTES
Author: Tormod Fjeldskår
.EXAMPLE
@tormodfj
tormodfj / profiles.json
Created October 24, 2019 12:19
My Windows Terminal settings
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"profiles":
[
{
"guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"hidden": false,
@tormodfj
tormodfj / List-RequiredRights.ps1
Created July 11, 2019 07:16
Parsing Swagger and listing x-required-rights
param (
[string]$SwaggerUrl,
[switch]$Pretty = $false
)
$paths = Invoke-WebRequest $swaggerUrl | ConvertFrom-Json | Select-Object -ExpandProperty paths
$result = @() # result array
foreach ($prop in $paths.PSObject.Properties) {
$pathName = $prop.Name
@tormodfj
tormodfj / ETag.cs
Last active July 17, 2019 07:25
Helper class for working with Entity Tags (ETags) in Web APIs
using System;
using System.Globalization;
namespace Common
{
/// <summary>
/// A value type representing an Entity Tag (ETag).
/// </summary>
public struct ETag : IFormattable
{
@tormodfj
tormodfj / Dockerfile
Last active August 7, 2018 07:36
Hvordan installere Seq lokalt med Docker
FROM microsoft/windowsservercore
LABEL Description="Seq Event Server" Vendor="Datalust" Version="4.2.1113"
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
RUN Invoke-WebRequest https://getseq.net/Download/Begin?version=4.2.1113 -OutFile c:\seq-installer.msi -UseBasicParsing ; \
Start-Process msiexec.exe -ArgumentList '/i c:\seq-installer.msi /quiet /norestart' -Wait ; \
Remove-Item c:\seq-installer.msi -Force
@tormodfj
tormodfj / clean-bin-obj.bat
Created August 14, 2017 11:56
Easily Clean Bin/Obj Folders
for /d /r . %%d in (bin,obj) do @if exist "%%d" rd /s/q "%%d"