Skip to content

Instantly share code, notes, and snippets.

@OnSive
OnSive / CloudConfig.md
Created October 20, 2023 09:48
My Hetzner Cloud Config (cloud-init)

What is Hetzner cloud config? https://community.hetzner.com/tutorials/basic-cloud-config

An additional feature during creation of a Hetzner cloud server (CX11 and above) is user data.
This allows the execution of a cloud-init configuration for the newly created server.

How to use:

  1. Replace both {username} with the username of your choise and remove both <--- Insert username
  2. Replace ssh-rsa AAA...0w== with your public ssh key and remove the <--- Insert public ssh key
  3. Copy & Paste your config in the Cloud-init configuration field at the bottom of the create server dialogue.

My cloud config does the following:

  • Creates a new user as admin and docker user and disables the need for a password on sudo ....
from urllib.request import pathname2url
import os.path
import sqlite3
import csv
db = r'karten.db'
con = sqlite3.connect(db)
cur = con.cursor()
def CheckDatabase():
@OnSive
OnSive / ipFunctions.cs
Last active April 26, 2021 13:02
Get private and public IP
#region Local & Public IP
/// <summary>
/// Returns the local and public IP of a network interface
/// </summary>
public static bool GetIPAddresses(string interfaceId, out string localIp, out string publicIp)
=> GetIpAddresses(NetworkInterface.GetAllNetworkInterfaces()
.FirstOrDefault(x => string.Compare(x.Id, interfaceId, StringComparison.Ordinal) == 0),
out localIp, out publicIp);
/// <summary>
@OnSive
OnSive / GetUserAsync_Fix.cs
Last active February 9, 2021 16:05
[GetUserAsync with IdentityServer Fix] Let you use the UserManager.GetUserAsync function again #Blazor #IdentityServer
/* Add following code to the server Startup.cs file */
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
// Add this configuration of the IdentityServer options
// https://github.com/dotnet/AspNetCore.Docs/issues/17517#issuecomment-605993247
@OnSive
OnSive / getParentWindow.cs
Created January 8, 2021 07:39
[Get parent window] Get parent window of any DependencyObject #C# #WPF
Window.GetWindow(this); // or ...(MyDependencyObject);
@OnSive
OnSive / TaskDelay.cs
Created December 10, 2020 10:11
[Deleay execution] Delay execution without a timer or Thread.Sleep #Threading
await Task.Delay(250);
@OnSive
OnSive / CustomEvent.vb
Last active February 9, 2021 16:07
[Custom event] A full custom event #Event
Public Class FooBar
Public Delegate Sub FooBarChanged(sender As Object, e As FooBarEventArgs)
Public Event OnFooBarChange As FooBarChanged
Private Sub RaiseEvent()
RaiseEvent OnFooBarChange(Me, new FooBarEventArgs(123))
End Sub
End Class
@OnSive
OnSive / DeserializeXml.cs
Last active December 8, 2020 09:33
[XML de-/serialization] Convertion between XML and objects #XML #Serialize
using System.IO;
using System.Text;
using System.Xml.Serialization;
/// <summary>
/// Converts an XML string to a class (XML import)
/// </summary>
/// <typeparam name="TReturn">The class to which the XML should be converted</typeparam>
public static TReturn DeserializeXml<TReturn>(this string sXml)
{
@OnSive
OnSive / FixLength.cs
Created December 8, 2020 09:21
[Fix length] Returns a string with a fixed length #Text
/// <summary>
/// Returns a string with a fixed length
/// </summary>
/// <param name="sText">The text which should be checked</param>
/// <param name="iLength">The wished length of the text</param>
/// <param name="bKeepEnd">If instead of cutting the end, the beginning should be cut</param>
/// <returns>
/// Returns the text with the passed length. Either its cut at the end or beginning, or filled up with
/// spaces.
/// </returns>
@OnSive
OnSive / SetCulture.cs
Last active December 8, 2020 09:17
[Set culture] Overwrites the currently set Culture #Culture #Configruation
using System;
using System.ComponentModel;
using System.Globalization;
/// <summary>
/// Overwrites the currently set Culture
/// </summary>
public static void SetCulture(string sName)
// Reading out culture from the Enum