Skip to content

Instantly share code, notes, and snippets.

@zett42
zett42 / static_transparent_F0F0F0.cpp
Last active June 25, 2019 20:20
CStatic transparent color 0xF0F0F0
// In OnInitDialog()
CRect rc; GetClientRect( rc );
CDC* winDC = GetDC();
CDC memDC; memDC.CreateCompatibleDC( winDC );
int const savedDC = memDC.SaveDC();
m_bitmap.CreateCompatibleBitmap( winDC, rc.Width(), rc.Height() );
memDC.SelectObject( m_bitmap );
@zett42
zett42 / SerializeEnumWrapper.test.ts
Last active January 4, 2020 23:27
@SerializeEnumWrapper - a decorator function for enum wrapper classes that adds metadata for serialization and reflection
/*
Copyright (c) 2020 zett42.
https://github.com/zett42
MIT License
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
@zett42
zett42 / jenkinsfile
Last active February 26, 2020 16:41
Call groovy function from Jenkins pipeline
pipeline {
agent any
stages {
stage('Test') {
steps {
myfun()
}
}
}
}
@zett42
zett42 / EditConsoleInput.ps1
Last active April 25, 2024 22:02
Edit PowerShell console input in external editor
#---------------------------------------------------------------------------------------------------------------
# Defines keyboard shortcut Alt+E for the console to edit current input in VSCode
# (edit the line that starts with "code" to use another editor).
#
# This code is an extension of this StackOverflow answer:
# https://stackoverflow.com/a/71175083/7571258
#
# New features:
# - Saves/restores the current cursor position (if the text hasn't changed too much).
# - Passes the current cursor position to VSCode, so the editors cursor gets positioned as in the console.
@zett42
zett42 / XmlReaderSearcher.cs
Last active March 8, 2022 10:57
Fast XML search using XmlReader
/* Copyright 2022 zett42
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 USE OR OTHER
@zett42
zett42 / TemporaryTypeData.Tests.ps1
Last active March 27, 2022 19:58
Update PowerShell type data only temporary, while a given script block runs
# Pester tests for TemporaryTypeData.psm1
BeforeAll {
Import-Module $PSScriptRoot\TemporaryTypeData.psm1 -Force
}
Describe 'Invoke-WithTemporaryTypeData' {
It 'invokes a script block with temporary type data' {
@zett42
zett42 / FlattenCustomObjects.ps1
Last active December 22, 2022 13:50
Measure performance of various ways to flatten (unroll) nested PowerShell objects
<# Copyright 2022 zett42
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 USE OR OTHER
@zett42
zett42 / CalcLineAndColumn.cs
Last active May 21, 2022 17:16
Calculate line and column from character index
// Calculates line and column from character index.
(int, int ) CalcLineAndColumn( string text, int pos ) {
// Count the number of line breaks before pos.
int line = 0, lastLf = -1;
int lf = text.IndexOf( '\n' );
while( lf != -1 && lf < pos ) {
++line;
lastLf = lf;
lf = text.IndexOf( '\n', lf + 1 );
@zett42
zett42 / Benchmark_IndexOfFirstNonWhitespaceChar.cs
Last active May 26, 2022 19:36
Benchmark methods for getting index of first non-whitespace character in C#
using System;
using System.Linq;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Attributes;
using System.Text.RegularExpressions;
namespace Benchmark_IndexOfFirstNonWhitespaceChar {
class Program {
static void Main( string[] args ) {
@zett42
zett42 / CustomDslParser.cs
Last active May 28, 2022 21:22
Example for a custom DSL parser in C# using ReadOnlySpan<char>
/* Copyright 2022 zett42
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 USE OR OTHER