Skip to content

Instantly share code, notes, and snippets.

View Regenhardt's full-sized avatar

Marlon Regenhardt Regenhardt

  • Softfair
  • Terra
View GitHub Profile
#!meta
{"kernelInfo":{"defaultKernelName":"csharp","items":[{"aliases":[],"name":"csharp"}]}}
#!csharp
static string[] ones = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
static string[] teens = { "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
static string[] tens = { "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
static string[] suffixes = { "", "thousand", "million", "billion" };
@Regenhardt
Regenhardt / DictWithDefault.cs
Last active July 8, 2021 07:33
Is it a dictionary? Is it a value? Yes!
public class DictWithDefault<TKey, TValue>
{
public readonly TValue DefaultValue;
private readonly Dictionary<TKey, TValue> values = new Dictionary<TKey, TValue>();
public DictWithDefault(TValue defaultValue = default)
{
this.DefaultValue = defaultValue;
}
public class ExceptionHandler : IMiddleware
{
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
try
{
await next(context);
}
catch (Exception e)
{
sudo mkdir /home/steam/Valheim
cd /home/steam/Valheim
sudo /home/steam/steamcmd +login anonymous +force_install_dir /home/steam/Valheim +app_update 896660 validate +exit
sudo wget https://gist.githubusercontent.com/Regenhardt/29498e06af3c41091f53b6f8d7f3e1dc/raw/df2da2e4b6151dcb0ae33df2d2a88a4c329592a5/start_valheim.sh
cd /etc/systemd/system
sudo echo -e "[Unit]\nDescription=Valheim service\nWants=network.target\nAfter=syslog.target network-online.target\n\n[Service]\nType=simple\nRestart=on-failure\nRestartSec=10\nUser=steam\nWorkingDirectory=/home/steam/Valheim\nExecStart=/home/steam/Valheim/start_valheim.sh\n\n[Install]\nWantedBy=multi-user.target" > valheim.service
sudo chmod +x valheim.service
sudo systemctl daemon-reload
sudo systemctl start valheim
@Regenhardt
Regenhardt / install_steamcmd.sh
Last active February 25, 2021 15:14
Script that makes a user and installs steamCMD on Linux
# steamCMD user
sudo useradd -m steam
cd /home/steam
## 64-bit
sudo apt update && sudo apt upgrade
sudo apt install software-properties-common
sudo add-apt-repository multiverse
sudo dpkg --add-architecture i386
@Regenhardt
Regenhardt / update-teamspeak.sh
Last active February 3, 2021 14:10
Bash script to automatically update a teamspeak server in a given directory
echo 'Download latest server version'
wget https://teamspeak.com/versions/server.json -qO - | jq '.linux.x86_64.mirrors["teamspeak.com"]' | xargs wget
# unpack
echo 'Unpack'
tar -xjvf teamspeak3-server_linux*.tar.bz2
# backup ts3.sqlitedb
echo "Backup data from $1"
cp $1/ts3server.sqlitedb $1/ts3server.sqlitedb.bak -f
# copy over new stuff
echo "Updating $1"
namespace regenhardt
{
public static class TaskExtensions
{
public static async Task<T> Data<T>(this Task<Result<T>> result)
{
return (await result).Data;
}
}
}
#!/bin/sh
### BEGIN INIT INFO
# Provides: ts3
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: TS3-Server
# Description: Teamspeak 3 Server
### END INIT INFO
public static class SecureStringExtensions
{
public static string GetSHA512(this SecureString input)
{
using (var sha512 = SHA512.Create())
{
byte[] password = Encoding.UTF8.GetBytes(ToNormalString(input));
byte[] hash = sha512.ComputeHash(password);
return Encoding.UTF8.GetString(hash);
}
The element 'CodeSnippets' in namespace 'http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet' cannot contain text.
List of possible elements expected: 'CodeSnippet' in namespace 'http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet'