Skip to content

Instantly share code, notes, and snippets.

@TheXenocide
TheXenocide / sidebar.js
Created October 2, 2012 21:59
Float my tumblr sidebar
(function($) {
$(function() {
var $sidebar = $('#sidebar');
var $win = $(window);
var origOffset = $sidebar.offset().top;
$win.scroll(function() {
var top = $win.scrollTop();
var offset = $win.scrollTop() - $sidebar.offset().top;
var overlap = $sidebar.height() - $win.height();
delegate void SignalHandler(object, SignalEventArgs);
delegate void SignalErrorHandler(object, SignalErrorEventArgs);
interface ISignalRecipient {
void ProcessSignal(object sender, SignalEventArgs e);
void ProcessError(object sender, SignalErrorEventArgs e);
}
interface ISignalSource {
event SignalHandler SignalOccurred;
@TheXenocide
TheXenocide / TestClrMD.cs
Created March 6, 2014 23:46
In-progress abstraction around accessing heap data using ClrMD
// TODO: encapsulate runtime session, store heap, common general purpose types, stats, etc.
static ClrRuntime _runtime;
void Main()
{
DataTarget _target = DataTarget.LoadCrashDump("C:\\Temp\\MEM.DMP");
_target.SetSymbolPath(Environment.GetEnvironmentVariable("_NT_SYMBOL_PATH"));
var clrVer = _target.ClrVersions[0];
string dac = clrVer.TryGetDacLocation();
@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);
@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 / 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 / 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 / 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 / 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 / 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");