Skip to content

Instantly share code, notes, and snippets.

@TheXenocide
TheXenocide / TurnOffNumlock.cs
Created February 14, 2023 19:48
Quick and dirty way to turn off numlock. One of my laptops doesn't have a numlock key but apparently still has logic to use the right side of the keyboard as a number pad so whenever it was disconnected from dock while numlock was still on could be annoying.
void Main()
{
if (Console.NumberLock)
{
NativeMethods.SimulateKeyPress(NativeMethods.VK_NUMLOCK);
}
}
public static class NativeMethods
{
@TheXenocide
TheXenocide / ExtractedFromLINQPad.cs
Created February 6, 2023 16:56
Process Environment Variable Testing
void Main()
{
var psi = new ProcessStartInfo("cmd")
{
UseShellExecute = false
};
psi.Environment.OrderBy(kvp => kvp.Key).Dump("Current Process");
var original = new Dictionary<string, string>(psi.Environment);
@TheXenocide
TheXenocide / VisualStudioLightWindowsTerminal.json
Created January 20, 2023 20:07
Visual Studio Light Windows Terminal Theme
{
"background": "#FFFFFF",
"black": "#0C0C0C",
"blue": "#00008B",
"brightBlack": "#A9A9A9",
"brightBlue": "#0073FF",
"brightCyan": "#00FFFF",
"brightGreen": "#16C60C",
"brightPurple": "#8F08C4",
"brightRed": "#FF0000",
@TheXenocide
TheXenocide / Field Injection Prototype.cs
Last active November 7, 2022 18:28
Prototype LINQPad script for optimized injection into fields without relying on reflection. Uses similar strategies as serializers to reduce dynamic instance field assignment overhead.
void Main()
{
const int runCount = 1000000;
// GetUninitializedObject is a special instantiation method primarily used by serializers to skip calling constructors
// It creates a completely uninitialized instance of a managed type (all 0s/nulls/etc. no constructor/initialization logic called)
//var emptyInstance = FormatterServices.GetUninitializedObject(typeof(TestClass));
//emptyInstance.Dump("Empty");
//FancyReinjector.Reinject(emptyInstance);
//emptyInstance.Dump("Same Instance");
@TheXenocide
TheXenocide / Broken.cs
Created February 10, 2020 19:22
LINQPad MyExtensions Bug - ModalDumpContainer
void Main()
{
var dc = new ModalDumpContainer().Dump();
dc.CreateHyperlinq(() =>
{
dc.Content = File.ReadAllText(@"C:\Temp\SomeBiggerFile.txt");
dc.TitleContent = "SomeBiggerFile.txt";
}, "Show Modal Content").Dump();
@TheXenocide
TheXenocide / Stream.js
Created January 15, 2020 17:45
Prototype Blocking Streams Over SharedArrayBuffer With Web Workers
// this could take advantage of other text encodings using existing JS libraries, but for now just using UTF16 with no BOM and both state and current buffer length slots
// also could stand to be updated to use "let" where appropriate, etc. it was just a quick demo
function StreamWriter(sharedBuffer) {
// This could be optimized, but for simplicity, stateView is 2 UInt16s
// stateView[0] = stream state (
// 0 = ready for initialization,
// 1 = ready for final read
// 2 = ready for partial read,
// 3 = ready for next write
@TheXenocide
TheXenocide / StructuredLoggerExtensions.cs
Created January 8, 2020 21:58
StructuredLoggerExtensions
/// <summary>
/// ILogger extension methods for common scenarios.
/// </summary>
public static class LoggerExtensions
{
private static readonly Func<StructuredAndFormattedLogValues, Exception, string> _messageFormatter = MessageFormatter;
//------------------------------------------DEBUG------------------------------------------//
@TheXenocide
TheXenocide / LINQPadTextHighlight.cs
Last active July 12, 2018 16:33
Just a quick LINQPad extension method to highlight matched text in a string. Not thoroughly tested, but it seems to be working well for my needs.
void Main()
{
"Testing this neat thing out to see if there is highlighting 123456789 evenly".HighlightStringMatches("th", "esting this", "1", "2", "3", "4", "5", "6", "7", "8", "9").Dump();
}
public static class MyExtensions
{
public static string HtmlEncode(this string text)
{
@TheXenocide
TheXenocide / ExcelOutlinerGroupingMacro.vb
Last active July 19, 2020 20:59
When a column of period-delimited numerical hierarchy identifiers is selected, this macro automatically groups them together. Sourced from https://web.archive.org/web/20170424081712/http://www.relken.com/code-example/vba-code-set-row-outline-level-structured-numbers which I dug up because this SuperUser answer ( https://superuser.com/a/1252011 )…
Sub SetLevel()
' SETLEVEL sets the outline level for each selected row based on the depth of a structured number.
' When there is no structured number, the level is set to one higher than the previous number.
' Sets the level 0 to the first cell highlighted by the user. For example if 1.2.3 is the first
' cell, then 1.2.3.1 is level 1 and 1.2.3.1.1. is level 2 and so forth.
' If the first cell is not a number, then it is set to level 0, and all numbers start at 1.
'SYNTAX
' The user selects the range of structured numbers within the sheet, then runs this macro.
@TheXenocide
TheXenocide / Lunar.html
Last active August 29, 2015 14:01
A remake of one of the earliest games I ever ported to JavaScript. I decided to remake it this past weekend while showing the old one to my roommate. Complete re-implementation using AngularJS took about 4 hours.
<html>
<head><title>Lunar Lockout</title>
<script src="https://code.angularjs.org/1.2.9/angular.js"></script>
<script>
// note that ng-keydown is available since angular 1.1.5
var app = angular.module('lunar', []);
app.filter('range', function() {
return function(input, total) {
total = parseInt(total);