Skip to content

Instantly share code, notes, and snippets.

View DvdKhl's full-sized avatar
💭
Off by one

DvdKhl

💭
Off by one
View GitHub Profile
@DvdKhl
DvdKhl / BytesToIPAddress.sql
Last active May 29, 2022 22:20
SQL Server function to convert varbinary(16) IPv4/IPv6 addresses to its string (shortened) form
--Copyright (C) 2022 DvdKhl
--Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
--to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
--and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
--The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
--THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
--FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
--WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
@DvdKhl
DvdKhl / RecordDebugStackoverflow.cs
Created September 27, 2020 17:48
RecordDebugStackoverflow
using System;
using System.Collections.Immutable;
//.NET 5 RC1 / Visual Studio 2019 Preview (Version 16.8.0 Preview 3.1)
//1. Set breakpoint on Console.WriteLine
//2. Start debugging
//3. Hover ActiveModuleSet with mouse
namespace RecordDebugStackoverflow {
class Program {
@DvdKhl
DvdKhl / OverlapAsyncLock.cs
Last active March 24, 2018 08:51
Async/Await: Overlapping execution but only execute expensive task once per overlap
public class OverlapAsyncLock {
public class OverlapLock : IDisposable {
private bool isFirst;
private OverlapAsyncLock owner;
internal OverlapLock(bool isFirst, OverlapAsyncLock owner) {
this.isFirst = isFirst;
this.owner = owner;
}
#include <stdlib.h>
#include "stm32f1xx.h"
void TIM2_IRQHandler() {
if (TIM2->SR & TIM_SR_UIF) {
TIM2->SR &= ~TIM_SR_UIF;
GPIOC->BSRR = GPIOC->ODR & GPIO_ODR_ODR13 ? GPIO_BSRR_BR13 : GPIO_BSRR_BS13;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleColors {
class Program {
static void Main(string[] args) {
#include "AVD3NativeLibApi.h"
void* CRC32Create() {
uint8_t *b = (uint8_t*)malloc(4);
memset(b, 0xFF, 4);
return b;
}
void CRC32Transform(void* handle, uint8_t *b, int32_t length) {
uint64_t state64 = *(uint32_t*)handle;
using System;
using System.Diagnostics;
using System.Security.Cryptography;
namespace SHA1Test {
class Program {
static void Main(string[] args) {
var sha = SHA1.Create();
var sw = new Stopwatch();
@DvdKhl
DvdKhl / Hasher.htm
Last active June 3, 2016 20:30
JavaScript File Hasher ( asm.js )
<!DOCTYPE html>
<html>
<head>
<title>JS Ed2k File Hasher</title>
</head>
<body>
<input type="file" id="files" name="file" />
<div id="readBytesButtons"><button>Hash File</button></div>
<div>Read Speed: <span id="readspeed"/>mb/s</div>
@DvdKhl
DvdKhl / IBANChecksum.cs
Last active August 1, 2023 13:32
Fast C# IBAN Checksum Verifier / Validation
//Copyright (C) 2013 DvdKhl
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
//to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
//and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
//WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE