Skip to content

Instantly share code, notes, and snippets.

Avatar

Guiorgy Guiorgy

  • Ecopre
  • Georgia
View GitHub Profile
@Guiorgy
Guiorgy / SingleOrArrayJsonConverter.cs
Last active Apr 29, 2022
A System.Text.Json JsonConverter that deserializes both a single object and an array of object to allow for flexibility
View SingleOrArrayJsonConverter.cs
public sealed class SingleOrArrayJsonConverter : JsonConverterFactory
{
private JsonConverterFactory? _jsonConverterFactory = null;
private JsonConverterFactory GetJsonConverterFactory(Type typeToConvert)
{
if (_jsonConverterFactory == null)
{
ArgumentNullException.ThrowIfNull(typeToConvert, nameof(typeToConvert));
if (!typeToConvert.IsArray) throw new ArgumentException($"{nameof(typeToConvert)} must be an Array!");
@Guiorgy
Guiorgy / VigenereCipher.cs
Last active Sep 29, 2021
A simple implementation of the Vigenere Cipher in C#
View VigenereCipher.cs
// #define VERBOSE // define for debug logs
// By deafult the alphabet only includes Lowercase Latin letters and the space character
#define INCLUDE_UPPER // define to include Uppercase Latin letters
#define INCLUDE_NUMBERS // define to include numbers
#define INCLUDE_SYMBOLS // define to include other valid ASCII characters
// #define INCLUDE_GEORGIAN // define to include Georgian letters
#define IGNORE_INVALID_CHARACTERS // define to discard invalid characters without stopping the algorithm
using System;
@Guiorgy
Guiorgy / Makefile
Created Apr 15, 2021
C++ library Makefile template
View Makefile
# Makefile based on https://gist.github.com/rioki/3957339 and https://stackoverflow.com/a/12099167
PACKAGE = my_package
VERSION = 1.0.0
CXX ?= g++ -std=c++0x
CXXFLAGS += -march=native -I include -D VERSION=\"$(VERSION)\" -D MY_PACKAGE_EXPORTS
LDFLAGS +=
ifeq ($(OS),Windows_NT)
View constexpr Sieve of Eratosthenes example prime.cpp
// prime calculation based on https://gist.github.com/rongjiecomputer/d52f34d27a21b8c9c9e82ca85b806640
// add increase limits or it wont compile for sieveSize = 1000000 -fconstexpr-loop-limit=2000000 -fconstexpr-ops-limit=335544320
// use debug build.
// release build will optimize most of the loop away.
#include <chrono>
#include <iostream>
#include <numeric>
#include <span>
#include <stdio.h>
@Guiorgy
Guiorgy / ASCII_TO_GEORGIAN.sql
Created Dec 29, 2020
Create an SQL function that converts ASCII characters to Georgian. (Useful for storing Georgian strings in the database using the ASCII encoding to save space and improve compatibility)
View ASCII_TO_GEORGIAN.sql
CREATE FUNCTION [dbo].[ASCII_TO_GEORGIAN] (@ascii nvarchar(max))
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE @ret NVARCHAR(max);
SET @ret =
REPLACE(
REPLACE(
REPLACE(
REPLACE(
@Guiorgy
Guiorgy / git_cheat_sheet.png
Last active Jun 30, 2020
A settings.json file for the Windows Terminal
@Guiorgy
Guiorgy / ProgressNotificationManager.kt
Last active Mar 23, 2020
A NotificationManagerCompat wrapper made to simplify handling of progress notifications
View ProgressNotificationManager.kt
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.app.Notification
import android.app.NotificationChannel
import android.content.Context
import android.os.Build
import androidx.annotation.IntDef
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
View FileUtils.kt
private const val TAG = "FILE_UTILS"
private const val BUFFER_SIZE = 16384 // 16 * 1024
@Throws(IOException::class)
fun copyFile(inputStream: InputStream, dst: File) {
inputStream.use {
FileOutputStream(dst).use { outStream ->
val buffer = ByteArray(BUFFER_SIZE)
var bytesRead: Int = inputStream.read(buffer)
while (bytesRead != -1) {
@Guiorgy
Guiorgy / ReverseSeekBar.kt
Last active Feb 20, 2020
An Android SeekBar, that's flipped horizontally
View ReverseSeekBar.kt
class ReverseSeekBar : SeekBar {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {
init()
@Guiorgy
Guiorgy / PrimitiveContainerConverter.java
Created Jun 19, 2019
A simple List to primitive array, and primitive array to List converter
View PrimitiveContainerConverter.java
@SuppressWarnings({"WeakerAccess", "unused"})
public abstract class PrimitiveContainerConverter {
public interface ListByteRef extends Supplier<List<? extends Byte>> {}
/**
* Convert Lists of {@link Byte} to array of primitive type byte
*
* usage: array = toPrimitiveArray(() -> list);
*/
public static byte[] toPrimitiveArray(final ListByteRef byteListRef) {
List<? extends Byte> byteList = byteListRef.get();