Skip to content

Instantly share code, notes, and snippets.

View Guiorgy's full-sized avatar

Guiorgy Guiorgy

  • Ecopre
  • Georgia
View GitHub Profile
@Guiorgy
Guiorgy / appendNotice.ps1
Created March 19, 2024 17:48
Appends a GPLv3 liecense notice to the top of every C# source file
$comment = @"
/*
This file is part of [PROJECT] (Copyright © [YEAR] [AUTHOR]).
[PROJECT] is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
[PROJECT] is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Foobar. If not, see <https://www.gnu.org/licenses/>.
*/
"@
@Guiorgy
Guiorgy / build.sh
Last active April 23, 2024 13:02
Download the latest, or a specified, Fastfetch release source and build a DEB package
#!/usr/bin/env bash
# usage examples:
# $ ./build.sh
# $ ./build.sh 2.7.0
set -Eeo pipefail # exit on error
handle_error() {
error_code=$?
@Guiorgy
Guiorgy / DateTimeIsoExtensions.cs
Last active November 20, 2023 13:42
Convert a DateTime object to and from an ISO string faster than the builtin methods
namespace DateTimeIso;
public static class DateTimeIsoExtensions
{
/// <summary>
/// Converts <see cref="DateTime"/> into an ISO 8601:2004 string (<c>yyyy-MM-dd HH:mm:ss.fff</c>) faster than <see cref="DateTime.ToString"/>.
/// </summary>
/// <param name="dateTime">the <see cref="DateTime"/> to be converted.</param>
/// <param name="milliseconds">if <see langword="false"/>, milliseconds won't be shown (<c>yyyy-MM-dd HH:mm:ss</c>).</param>
/// <param name="strictDateTimeDelimiter">if <see langword="true"/>, <c>'T'</c> will be used as the delimiter between date and time as per ISO 8601-1:2019 (<c>yyyy-MM-ddTHH:mm:ss.fff</c>).</param>
#!/usr/bin/env bash
# NOTE: Deprecated in favor of https://github.com/Guiorgy/docker-vackup
# This is a wrapper for vackup: https://github.com/BretFisher/docker-vackup
# Installation:
# sudo curl -sSL https://raw.githubusercontent.com/BretFisher/docker-vackup/main/vackup -o /usr/local/bin/vackup && sudo chmod +x /usr/local/bin/vackup
# Based on PR #6: https://github.com/BretFisher/docker-vackup/pull/6
@Guiorgy
Guiorgy / CheckBoxLabeled.xaml
Created August 2, 2023 15:05
A custom MAUI view that combines a CheckBox with a Label and reacts to taps to both the CheckBox and Label
<?xml version="1.0" encoding="utf-8" ?>
<HorizontalStackLayout xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiExtensions.CheckBoxLabeled"
x:Name="this">
<!-- Color="{Binding Source={x:Reference this}, Path=Color}" -->
<CheckBox
x:Name="CheckBox"
IsChecked="{Binding Source={x:Reference this}, Path=IsChecked}"
@Guiorgy
Guiorgy / dictionary_generator.py
Created January 25, 2023 12:36
A Python generator that takes an alphabet string and word length, and generates words (character combinations from the alphabet) in the desired range
import itertools
import math
from typing import Optional, Generator
def dictionary_generator(alphabet: str, word_length: int, start: Optional[int] = None, stop: Optional[int] = None) -> Generator[str, None, None]:
def new_state(start=0, stop=None):
return itertools.islice(alphabet, start, stop)
if not alphabet:
@Guiorgy
Guiorgy / ReadOnlySpan.py
Last active January 24, 2023 21:29
A Python 3.11 implementation of a Read Only Span
import collections.abc
from typing import overload, Sequence, TypeVar, Optional, Self
_T_co = TypeVar("_T_co", covariant=True)
class ReadOnlySpan(collections.abc.Sequence):
def __init__(self, source: Sequence[_T_co], start: Optional[int] = None, length: Optional[int] = None):
if not isinstance(source, collections.abc.Sequence):
@Guiorgy
Guiorgy / git-aliases.sh
Last active February 23, 2024 11:35
Useful git aliases
#!/bin/bash
# Set the default branch name to main
git config --global init.defaultBranch main
# Alias for listing all defined aliases
git config --global alias.alias '! git config --get-regexp ^alias\. | sed -e s/^alias\.// -e s/\ /\ =\ /'
# Usage: git alias
# Alias for short/packed pretty logs
@Guiorgy
Guiorgy / MutableString.cs
Last active November 24, 2022 14:53
An "evil" C# wrapper class that allows the mutation of the internal string object
/// <summary>
/// <strong>This class uses unsafe code and is only meant as a thought experiment. Do NOT use this in production!</strong>
/// <para/>
/// A wrapper to a string object that allows the mutation of the said string.
/// </summary>
public sealed class MutableString
{
/**
* We are assuming that if we allocate a char[] array and write it in a specific way that
* taking a reference to one of it's elements, we can "fool" .NET into thinking that that's
@Guiorgy
Guiorgy / StringReplaceTokensBatchFast.cs
Last active November 15, 2022 16:01
Search occurrences of specified tokens (character sequences surrounded by specified prefix and postfix delimiters) in a string and replace them with other specified strings faster and with less memory usage
public static class StringExtensionMethods
{
/**
* Returns a new string in which all occurrences of specified tokens (character sequences surrounded
* by the specified prefix and postfix delimiters) in the current string are replaced with other specified strings.
*
* All tokens must start and end with the same prefix and postfix delimiters.
* `toReplace` strings in the batch should not have those delimiters explicitly included.
*/
public static string ReplaceBatch(this string origin, char prefix, char postfix, params (string toReplace, string replaceWith)[] batch)