Skip to content

Instantly share code, notes, and snippets.

View rudzen's full-sized avatar
💭
I may be slow to respond.

rudzen

💭
I may be slow to respond.
View GitHub Profile
@rudzen
rudzen / UUIDUtils.java
Created July 9, 2022 19:15 — forked from davidmc24/UUIDUtils.java
Convert Microsoft GUID to Java UUID
// Original source: https://github.com/zagyi/adsync4j/blob/master/core/src/main/java/org/adsync4j/impl/UUIDUtils.java
/*******************************************************************************
* ADSync4J (https://github.com/zagyi/adsync4j)
*
* Copyright (c) 2013 Balazs Zagyvai
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@rudzen
rudzen / MagicBB.java
Created August 9, 2020 08:13
Chess magic bitboard Java class (attacks for Bishop, Rook & Queen) as bitboards.
/*
*Copyright (C) 2007 Pradyumna Kannan.
*
*This code is provided 'as-is', without any expressed or implied warranty.
*In no event will the authors be held liable for any damages arising from
*the use of this code. Permission is granted to anyone to use this
*code for any purpose, including commercial applications, and to alter
*it and redistribute it freely, subject to the following restrictions:
*
*1. The origin of this code must not be misrepresented; you must not
@rudzen
rudzen / XmlSerializer.cs
Created March 7, 2020 22:09
XmlSerializer (C# 8.0+)
/// <summary>
/// Simple async XML serializer by Rudy A. Kohn
/// MIT License: https://en.wikipedia.org/wiki/MIT_License
/// </summary
public static class XmlSerializer
{
/// <summary>
/// Remove xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
/// By adding an empty namespace mapping
/// </summary>
@rudzen
rudzen / FastUnsafeStringBuilder.cs
Created February 12, 2020 06:00
Concat ReadOnlySpan<char>
public ref struct FastUnsafeStringBuilder {
private string s;
private int pos;
public FastUnsafeStringBuilder(int maxlength) {
s = new string('\0', maxlength);
pos = 0;
}
public unsafe void Append(ReadOnlySpan<char> str) {
@rudzen
rudzen / GenerateSitecoreNugetPackages.ps1
Created September 18, 2018 14:57 — forked from asmagin/GenerateSitecoreNugetPackages.ps1
Powershell script to generate nuget packages with dependencies
param(
[string] $Major = "8",
[string] $Minor = "1",
[string] $Update = "0",
[string] $Date = "151003",
[string] $nugetPath = ".\tools\nuget.exe",
[string] $downloadsPath = ".\downloads",
[string] $nuspecTemplate = ".\tools\package.nuspec.xml",
[string] $apiKey,
[string] $nugetFeed = "http://use-your.own/nuget/Sitecore-Libs"
@rudzen
rudzen / vec_resize.hpp
Created August 19, 2018 19:54
Simple C++ vector size align function
// Will resize a vector based on a specified size.
// Can perform a specified function after resizing
// For non-copy constructables it will just reassign the vector
template<typename T, typename PerformAfter>
void align_vector_size(std::vector<T> &vec, const size_t size, const PerformAfter func) {
if constexpr (std::is_copy_constructible_v<T>)
{
if (vec.size() != size)
@rudzen
rudzen / str_to_integral.hpp
Created August 3, 2018 17:52
C++17 simple string to integral
#include <string_view>
namespace Math {
/// Determin if a value is in between (inclusive) to boundries
template<int min, int max>
constexpr bool in_between(const int value) {
return (static_cast<unsigned int>(value) - static_cast<unsigned int>(min) <= static_cast<unsigned int>(max) - static_cast<unsigned int>(min));
}
@rudzen
rudzen / vector.hpp
Last active June 15, 2018 12:46
Simple subclass of std::vector for specific purpose. Without move related operations.
template<typename T>
class Vector : public std::vector<T> {
public:
Vector() = default;
explicit Vector(const T &t) noexcept : std::vector<T>(t, 1) {}
void append(const T element, const Vector<T> &vec) noexcept {
append(element);
std::vector<T>::reserve(vec.size() + 1);
for (const auto &v : vec)
std::vector<T>::emplace_back(v);
@rudzen
rudzen / EmailVerification.cs
Created June 11, 2018 11:32
C# simple email validation with RegEx
namespace Validation
{
public static partial class Validate
{
private const string EmailRegex = @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";
private static readonly Regex Regex = new Regex(EmailRegex);
public static bool IsEmail(this string @this)
@rudzen
rudzen / buff.hpp
Created May 2, 2018 12:08
Set console in/out buffer
#ifndef RDZ_UTILS_CIOBUF_HPP
#define RDZ_UTILS_CIOBUF_HPP
#include <iostream>
namespace util
{
/**
* \brief Configure console input buffer size
* \tparam buffer The buffer size