Skip to content

Instantly share code, notes, and snippets.

@nzbart
nzbart / Directory.Build.props
Created February 26, 2020 23:16
Disable Roslyn analysis for debug builds, but keep real-time analysis in IDEs and release mode builds.
<Project>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
</PropertyGroup>
</Project>
@nzbart
nzbart / join.sh
Created January 21, 2020 20:26
Join Ubuntu Server to Active Directory (AD) domain
#Optional steps:
#apt update && apt full-upgrade -y && apt auto-remove -y
#apt install -y vim-nox
apt install -y packagekit realmd
pam-auth-update --enable mkhomedir
echo '%domain\ admins@example.com ALL=(ALL:ALL) ALL' > /etc/sudoers.d/example
realm join -v -U domain_admin_user_name example.com
@nzbart
nzbart / DownloadAllCommandLineHeroesEpisodes.sh
Last active July 24, 2019 03:31
Download all episodes of Red Hat's Command Line Heroes as MP3 files. Using the command line, of course.
#!/usr/bin/sh
curl -Ss https://feeds.pacific-content.com/commandlineheroes | hxnormalize -ex | hxselect "enclosure[url\$='.mp3']::attr(url)" -c -s '\n' | xargs -n 1 curl -LO
@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 / Get-WebRequestSummary.psm1
Last active November 1, 2018 20:23
Get-WebRequestSummary returns a list of requests currently executing against IIS 8 (Windows 8 or Windows Server 2012).
Add-Type -TypeDefinition @"
[System.FlagsAttribute]
public enum PipelineStateFlags
{
Unknown = 0,
BeginRequest = 1,
AuthenticateRequest = 2,
AuthorizeRequest = 4,
ResolveRequestCache = 8,
MapRequestHandler = 16,
@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 / ComEmuTasks
Last active February 18, 2018 21:31
ConEmu task for launching PowerShell with the Visual Studio environment variables and path correctly configured.
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" & powershell" -new_console:d:D:\Dev
Admin:
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat" & powershell" -new_console:a