Skip to content

Instantly share code, notes, and snippets.

View VenenJean's full-sized avatar
:octocat:
Autonomous Developer

♦ Venen Jean ♦ VenenJean

:octocat:
Autonomous Developer
View GitHub Profile
@VenenJean
VenenJean / Hashing.cs
Created November 12, 2023 14:31
Hashing with SHA512 in C# (Salt + Pepper).
using System;
using System.Security.Cryptography;
using System.Text;
public class Hasher {
private static readonly RandomNumberGenerator Rng = RandomNumberGenerator.Create();
public string CreateHash(string input, byte[] salt, string pepper) {
byte[] saltBytes;
byte[] pepperBytes = Encoding.UTF8.GetBytes(pepper);
@VenenJean
VenenJean / WSL-MariaDB-SSH.cs
Last active September 25, 2023 05:15
Example code on: Connecting to a MariaDB Server which is running on a Debian WSL2 VM via a SSH tunnelled passphrase ED2519 encrypted connection. Use only if your MariaDB server AND the SSH server have the same host!!!
using MySqlConnector;
using Renci.SshNet;
class Program {
static void Main(string[] args) {
// SSH Connection Information
string sshHost = ""; // SSH server IP or hostname
string sshUsername = ""; // Debian run `whoami`
string sshPrivateKeyPath = ""; // Path to ED25519 private key
string sshPrivateKeyPassphrase = ""; // ED25519 private key passphrase

20 useful C# features

Null-Conditional Operator (?)

The null-conditional operator allows you to safely access properties or call methods on an object that might be null without causing a null reference exception.
Example: int? length = text?.Length;

String Interpolation...

String interpolation simplifies string formatting by allowing you to embed expressions directly within a string using the $ symbol.
Example: string name = "Alice"; string message = $"Hello, {name}!";

We couldn’t find that file to show.

Using the 'File' (System.IO) class for reading and writing data

  • File.ReadAllText(filePath); -> Reads / Returns the data of a file as STRING

  • File.ReadAllLines(filePath); -> Reads /Returns the contents of a file and stores each line at a new index in a STRING[]

  • File.ReadAllBytes(filePath); -> Reads / Returns the contents of a file as binary data and stores the data in a BYTE[]

  • File.WriteAllText(filePath, data); -> Overwrites the content with the content of a string variable

  • File.WriteAllLines(filePath, data); -> Write content of a string array - each entry = new line

  • File.AppendAllText(filePath, data); -> Appends STRING

  • File.AppendAllLines(filePath, data); -> Append content of a string array

C++ Notes

Notes I took while learning C++.

Escape codes

std::endl; -> No escape code | Adds a new line and flushes the buffer
std::cout << "\n"; -> New line | Recommended in most cases instead of "std::endl"
std::cout << "\t"; -> Horizontal Tab