Skip to content

Instantly share code, notes, and snippets.

Avatar
🔏
;ÿÿÿÿrules

Chris S. yetanotherchris

🔏
;ÿÿÿÿrules
View GitHub Profile
@yetanotherchris
yetanotherchris / http-load-test.ps1
Created Mar 30, 2022
Powershell HTTP "load testing" (about 3-5 RPS)
View http-load-test.ps1
while ($true) { $r = wget -uri "http://somesite.com?q=1" -headers @{"Accept-Tenant"="Nz"}; echo $r.Content }
@yetanotherchris
yetanotherchris / monitor-speed.ps1
Created Mar 14, 2022
Monitor internet speed test in Powershell
View monitor-speed.ps1
# choco install -y jq
# npm install --global fast-cli
while ($true)
{
$now = date;
$dateRow = $now.ToString("dd-MM-yyyy HH:mm");
$dl = fast -u --json | jq '.downloadSpeed';
echo "$dateRow, $dl" >> data.txt;
@yetanotherchris
yetanotherchris / TestCircuitBreaker.Controllers.HomeController.cs
Last active Aug 21, 2021
Polly CircuitBreaker, Retry and Timeout configuration example for HttpClient and HttpClientFactory
View TestCircuitBreaker.Controllers.HomeController.cs
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using TestCircuitBreaker.Models;
@yetanotherchris
yetanotherchris / loading-pem-ssl-windows-workaround.cs
Created Dec 26, 2020
Loading PEM SSL certificates in Kestrel (Windows work-around)
View loading-pem-ssl-windows-workaround.cs
// See https://github.com/dotnet/runtime/issues/23749
public static class CertHelper
{
// To generate a self-signed cert:
// dotnet dev-certs https -ep $pwd/selfsigned.pem --format Pem -np
public static X509Certificate2 GetCertificate()
{
X509Certificate2 sslCert = CreateFromPublicPrivateKey("certs/selfsigned.pem", "certs/selfsigned.key");
@yetanotherchris
yetanotherchris / main.go
Last active Nov 27, 2020
Quote of the day in Go Lang (playing with Go for the first time)
View main.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
@yetanotherchris
yetanotherchris / yarn-env-bars.ps1
Last active Nov 21, 2020
Solution to yarn global add does not work on Windows (command not found)
View yarn-env-bars.ps1
$yarnPath = & yarn global bin
$path = [System.Environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::User)
[System.Environment]::SetEnvironmentVariable("PATH", "$path;$yarnPath", [System.EnvironmentVariableTarget]::User)
# Your yarn path should appear at the end of the path now
[System.Environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::User)
# Try a global command, for example gatsby. If you're using Visual Studio Code, you'll need to restart the IDE
gatsby
@yetanotherchris
yetanotherchris / PublicKeyCryptographyExample.cs
Last active Apr 4, 2022
Public key cryptography by example in .NET Core
View PublicKeyCryptographyExample.cs
using System;
using System.IO;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace PublicKeyCryptographyExample
{
//
// https://yetanotherchris.dev/security/public-private-key-in-netcore-by-example/
//
@yetanotherchris
yetanotherchris / quote-of-the-day.ps1
Created Nov 3, 2020
Quote of the day Powershell script
View quote-of-the-day.ps1
wget "http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en" | Select-Object -Expand Content | ConvertFrom-Json | Select-Object quoteText, quoteAuthor
@yetanotherchris
yetanotherchris / base64-decode-jwt.cs
Last active Sep 15, 2020
Base64 decode a JWT in C# .NET Core
View base64-decode-jwt.cs
// Add the following nuget package for Base64Url decoding:
// dotnet add package Microsoft.AspNetCore.WebUtilities
// This example JWT is taken from jwt.io
string jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
string[] parts = jwt.Split('.');
foreach (string section in parts)
{
// The final (3rd) section is the JWT signature, so will appear as nonsense as it isn't JSON
@yetanotherchris
yetanotherchris / aws.sh
Created Aug 3, 2020
A few AWS command lines
View aws.sh
aws s3api create-bucket --bucket MYBUCKET --create-bucket-configuration LocationConstraint=eu-west-1
aws s3api put-object --bucket MYBUCKET --key myfile.txt --body .\myfile.txt
aws dynamodb create-table --table-name {YOURTABLE} &
--attribute-definitions AttributeName={SOME-STRING-ID},AttributeType=S AttributeName={SOME-NUMBER-ID},AttributeType=N &
--key-schema AttributeName={SOME-STRING-ID},KeyType=HASH AttributeName={SOME-NUMBER-ID},KeyType=RANGE &
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5