Skip to content

Instantly share code, notes, and snippets.

@vchirikov
vchirikov / vscode-keybindings-alt+hjkl-zation.py
Created December 9, 2020 09:21 — forked from 3v1n0/vscode-keybindings-alt+hjkl-zation.py
Make VSCode default key-bindings more HJLK friendly using Alt to alternate to them
#/usr/bin/python3
import json
import sys
import os
import re
import copy
input = sys.argv[1]
@vchirikov
vchirikov / style.css
Last active August 24, 2020 12:29
vs code useful fixes
/*
https://marketplace.visualstudio.com/items?itemName=be5invis.vscode-custom-css
https://marketplace.visualstudio.com/items?itemName=lehni.vscode-fix-checksums
*/
.loopText tspan {
fill: white;
background: white;
}
/* removes underscore style on links */
@vchirikov
vchirikov / settings.json
Created June 7, 2020 14:26
Windows Terminal config
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"alwaysShowTabs": true,
"confirmCloseAllTabs": true,
"showTabsInTitlebar": true,
"defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
"initialCols": 170,
"initialRows": 60,
@vchirikov
vchirikov / MurmurHash3.cs
Last active May 2, 2020 22:15
MurmurHash3
public interface IHashFunction
{
/// <summary>
/// Computes the 32-bit hash for the <seealso cref="ReadOnlySpan{T}"/>
/// </summary>
byte[] ComputeHash128(in ReadOnlySpan<byte> buffer);
/// <summary>
/// Computes the 128-bit hash for the <seealso cref="ReadOnlySpan{T}"/>
/// </summary>
@vchirikov
vchirikov / bench_for_kirill.cs
Created April 1, 2020 19:11
twitter_sort_bench
using System;
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
[MemoryDiagnoser]
[MinColumn, MaxColumn]
[MarkdownExporterAttribute.GitHub]
[GcServer(true)]
@vchirikov
vchirikov / Benchmark.md
Created March 22, 2020 19:26 — forked from buybackoff/Benchmark.md
Avx2/branch-optimized binary search in .NET

Binary search is theoretically optimal, but it's possible to speed it up substantially using AVX2 and branchless code even in .NET Core.

Memory access is the limiting factor for binary search. When we access each element for comparison a cache line is loaded, so we could load a 32-byte vector almost free, check if it contains the target value, and if not reduce the search space by 32/sizeof(T) instead of 1 element.

AVX512 with _mm256_cmpge_epi64_mask instruction should improve it even more, but it is not available on .NET yet.

Results for long. Searching [0,1,2,3,...] in [0,2,4,6,...] array (50% hit rate)

SearchBench

@vchirikov
vchirikov / index.html
Created March 19, 2020 19:30 — forked from SQL-MisterMagoo/index.html
Monitor Blazor WASM loading and report errors
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Blazor Loading</title>
<base href="/" />
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="css/site.css" rel="stylesheet" />
</head>
@vchirikov
vchirikov / _notes.md
Created March 12, 2020 06:56
AppDomainManager Injection

Let's turn Any .NET Application into an LOL Bin

We can do this by experimenting with .config files.

Many defenders catch/detect files that are renamed, they do this by matching Original Filename to Process Name

In this example, we don't have to rename anything. We simple coerce a trusted signed app to load our Assembly.

We do this by directing the application to read a config file we provide.

@vchirikov
vchirikov / Microsoft.PowerShell_profile.ps1
Last active August 17, 2020 07:40
Powershell profile
Import-Module PSReadLine
# zsh-like menu complete, for bash-like use `Complete`
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadlineOption -ShowToolTips
Set-PSReadlineOption -BellStyle None
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
Import-Module posh-git
@vchirikov
vchirikov / ReflectionVsTypeloader.cs
Created January 24, 2020 22:58 — forked from ilmax/ReflectionVsTypeloader.cs
Reflection vs TypeLoader
void Main()
{
BenchmarkRunner.Run<TypeBenchmark>();
BenchmarkRunner.Run<FieldsBenchmark>();
BenchmarkRunner.Run<PropertiesBenchmark>();
BenchmarkRunner.Run<MethodsBenchmark>();
}
// Define other methods and classes here
[MemoryDiagnoser]