Skip to content

Instantly share code, notes, and snippets.

@nzbart
nzbart / Readme.markdown
Last active January 29, 2019 22:27
This is an attempt to reproduce the issue downloading files in headless Chrome, as reported at: https://bugs.chromium.org/p/chromium/issues/detail?id=916113
@nzbart
nzbart / Code.cpp
Created November 13, 2018 00:18
Configure Windows for ANSI escape sequences to allow colour output in cross-platform manner
void configure_console_for_ansi_escape_sequences()
{
auto const console_window = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD startup_console_mode;
GetConsoleMode(console_window, &startup_console_mode);
SetConsoleMode(console_window, startup_console_mode | 0x0004);
}
@nzbart
nzbart / Decrypt.ps1
Last active September 19, 2018 00:28
Encryption and decryption using public TLS certificate. This is useful if you want someone to encrypt data to send to you, and you have access to the private key for a public website.
$certPassword = Read-Host "Certificate password"
$fullCertBytes = <certificate>
$fullCert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$fullCert.Import($fullCertBytes, $certPassword, 0)
$encrypted = [Convert]::FromBase64String((Read-Host "Encrypted password"))
[System.Text.Encoding]::UTF8.GetString(($fullCert.PrivateKey.Decrypt($encrypted, $true)))
@nzbart
nzbart / UptimeRobot.R
Created April 27, 2018 19:21
Parse a CSV file exported from Uptime Robot to get a summary of outages over the past year.
if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse, lubridate, pander)
inputFileName <- file.choose()
rawData <- read_csv(inputFileName, locale = locale(tz = Sys.timezone()), col_types = cols(
Event = col_character(),
`Date-Time` = col_datetime(format = ""),
Reason = col_factor(levels = NULL),
Duration = col_character(),
`Duration (in mins.)` = col_integer()
@nzbart
nzbart / CommitToGitInBatches.ps1
Last active March 29, 2018 20:19
Quick and dirty script to commit a large number / size of files in smaller batches. Most Git cloud providers don't like to receive enormous pushes and will drop the connection.
git push
$deletedFiles = @(git ls-files --deleted)
if($deletedFiles.length -ne 0) {
$deletedFiles | % { git rm $_ }
git commit -m "Deleted some files"
}
$f = git status --porcelain=v1 -u
if(!$?) { throw "Failed." }
@nzbart
nzbart / Repro.cmd
Last active March 22, 2023 02:19
How to use `git bisect run` with a PowerShell script to reproduce an issue, for example a test that has started failing recently.
powershell -command %~dpn0.ps1
#Requires -RunAsAdministrator
choco install -y miktex pandoc
# Run with:
# pandoc .\MyDocument.markdown -o MyDocument.pdf --latex-engine xelatex -V "mainfont=Segoe WP" -V geometry:margin=2.5cm -V fontsize=12pt -V papersize=A4
#Requires -RunAsAdministrator
choco install -y python2-x86_32 miktex
python -m pip install --upgrade pip
python -m pip install pygments
$path = [Environment]::GetEnvironmentVariable('PATH', 'Machine')
$scriptPath = 'C:\tools\python2-x86_32\Scripts'
if($path -notlike ("*" + $scriptPath + "*")) {
[Environment]::SetEnvironmentVariable('PATH', "$PATH;$scriptPath", 'Machine')
Chocolatey is running on Windows v 10.0.10586.0
Attempting to delete file "C:/ProgramData/chocolatey/choco.exe.old".
Attempting to delete file "C:\ProgramData\chocolatey\choco.exe.old".
Command line: "C:\ProgramData\chocolatey\choco.exe" install planexplorerssmsaddin -debug -verbose -y -force
Received arguments: install planexplorerssmsaddin -debug -verbose -y -force
NOTE: Hiding sensitive configuration data! Please double and triple
check to be sure no sensitive data is shown, especially if copying
output to a gist for review.
Configuration: CommandName='install'|CacheLocation='D:\Temp'|
@nzbart
nzbart / CreateAspNetSynchronizationContext.cs
Last active October 22, 2015 21:13
Create an instance of the AspNetSynchronizationContext, which is internal and is not easily constructed.
static SynchronizationContext CreateAspNetSynchronizationContext()
{
const string taskFriendlyConfigName = "aspnet:UseTaskFriendlySynchronizationContext";
var originalConfigSetting = ConfigurationManager.AppSettings[taskFriendlyConfigName];
ConfigurationManager.AppSettings[taskFriendlyConfigName] = "true";
try
{
TextWriter writer = new StringWriter();
HttpRequest rx = new HttpRequest("", "http://example.com", "");
HttpResponse tx = new HttpResponse(writer);