Skip to content

Instantly share code, notes, and snippets.

@xoofx
xoofx / BatchFinder.cs
Last active June 21, 2024 11:52
Optimized AVX2 version of finding the index of an integer from an array
// Discussion about https://mastodon.social/@denisio@dotnet.social/110644302160625267
// Optimized version using AVX. From 4x to 10x faster than a simple version.
// - nint for indexing
// - Unsafe.Add
// - Unrolling of 4 Vector256 + Or of the results to have only 1 branch per loop
// - Finding the local index within the Vector256 without a loop using AVX movemask
// Similar code can be done for Vector128
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@dr4k0nia
dr4k0nia / Suscall.cs
Created August 3, 2021 13:30
An example of using x64 syscall shellcode to call NtProtectVirtualMemory
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Code_Projects
{
public unsafe class Suscall
{
[DllImport("kernel32", SetLastError = true)]
@mgraupner
mgraupner / gist:e061079e96669b7b4ff2d1e64619f15a
Last active September 28, 2021 10:22
Create a Caddy 2 server HTTP Basic Authentication password
As there are no clear instructions on the Caddy Homepage on how to create a password
(without their own caddy tool, which might not be available) in the needed format,
I compiled a short list on how to do it the right way:
Replace password with your own password!
Create a BCrypt encrypted password in 10 rounds
htpasswd -bnBC 10 "" password
->
:$2y$10$ow7UC86yXaSoZSr0mcGxeOYK9DfqsnKnA9RoKR.nxUUXVbXqOibgm
@StephenCleary
StephenCleary / AsyncCache.cs
Last active April 15, 2024 10:22
Asynchronous cache
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;
using Nito.Logging;

Various search databases and backends as alternatives to Elasticsearch.

Rust

@default-writer
default-writer / BufferSegment.cs
Created March 27, 2019 10:08
Queued ArrayPool<T> memory strings
public class BufferSegment : IDisposable
{
public BufferSegment(int size) => Buffer = ArrayPool<byte>.Shared.Rent(size);
public byte[] Buffer { get; }
public int ReadBytes { get; set; }
public int WrittenBytes { get; set; }
using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
namespace TlsSpy
.NET Core 2.2.0 (CoreCLR 4.6.27110.04, CoreFX 4.6.27110.04), 64bit RyuJIT
BranchmarkString.Benchmark.V6()
return string.Create(13, _id, (buffer, id) =>
^^^
{
^^^
var encode32CharsArray = _encode32CharsArray;
^^^
buffer[12] = encode32CharsArray[id & 31];
^^^
@janeczku
janeczku / 00-cloud-config.yml
Last active May 24, 2024 04:06
Annotated RancherOS Cloud-init configuration snippets
#cloud-config
# Set the hostname for this machine (takes precedence over hostname assigned by DHCP lease).
hostname: myhost
# Authorize SSH keys for the `rancher` sudoer user
ssh_authorized_keys:
- ssh-rsa AAA...ZZZ example1@rancher
@tylerchr
tylerchr / Dockerfile
Created July 21, 2018 01:37
Compiling V8 for alpine (link against musl)
#
# Building V8 for alpine is a real pain. We have to compile from source, because it has to be
# linked against musl, and we also have to recompile some of the build tools as the official
# build workflow tends to assume glibc by including vendored tools that link against it.
#
# The general strategy is this:
#
# 1. Build GN for alpine (this is a build dependency)
# 2. Use depot_tools to fetch the V8 source and dependencies (needs glibc)
# 3. Build V8 for alpine