Skip to content

Instantly share code, notes, and snippets.

@nzbart
nzbart / Readme.markdown
Created June 2, 2019 20:02
Change WSL to debian testing
  1. Replace the existing sources.list with the on in this Gist.
  2. apt update && apt full-upgrade -y
@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
@nzbart
nzbart / get_lists.py
Created September 28, 2021 22:21
Microsoft Todo query using Microsoft Graph
from msal import PublicClientApplication
import requests
def get_authorisation_token():
app = PublicClientApplication(
"***Your Application (client) ID****",
authority="https://login.microsoftonline.com/consumers")
scopes = [
@nzbart
nzbart / CredWriteAndReadWithProfileLoad.cpp
Last active February 26, 2021 03:27
Read / write credentials through CredRead and CredWrite, with a profile load for good measure. Fails under PowerShell remoting.
#include <SDKDDKVer.h>
#include <tchar.h>
#include <Windows.h>
#include <WinCred.h>
#include <Userenv.h>
#include <atlsecurity.h>
#include <Lmcons.h>
#include <iostream>
@nzbart
nzbart / backup.sh
Last active June 29, 2020 07:13
Script to backup minecraft server once a day to mega.nz (needs to be run manually)
#!/bin/bash
set -e
BACKUPDIR="../minecraft-backups"
set_most_recent_backup_file() {
MOSTRECENTLOCALBACKUPFILE=$(find "$BACKUPDIR" -type f -printf '%f\n' | sort -r | head -1)
echo "Most recent local backup file: $MOSTRECENTLOCALBACKUPFILE"
}
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
ssh-keyscan localhost | ssh-keygen -lf -
@nzbart
nzbart / NetworkCapture.psm1
Last active May 12, 2020 15:45
Run a network capture on Windows without installing Wireshark or any other tools on your servers.
#requires -version 3
$ErrorActionPreference = 'Stop'
$networkTraceFileName = 'NetworkTrace'
function LaunchSingleRemoteCommand([string][parameter(mandatory)]$ComputerName, [pscredential]$Credential, [System.Management.Automation.Runspaces.AuthenticationMechanism]$Authentication, [scriptblock][parameter(mandatory)]$ScriptBlock)
{
$args = @{
ComputerName = $ComputerName
@nzbart
nzbart / join-domain.sh
Last active May 1, 2020 13:34
Join a Debian/Ubuntu based server to a Windows domain so that users can ssh with domain credentials
# Replace example.com with your domain
hostnamectl set-hostname <hostname>.example.com # FQDN required for DNS registrations by realm (not sure why)
mkdir -p /var/log/journal # Persist logs across reboots
apt update && apt full-upgrade -y && apt auto-remove -y # Get software up to date
apt install -y unattended-upgrades packagekit realmd dnsutils sudo # Install required packages
pam-auth-update --enable mkhomedir # Allow automatic creation of home directories for domain users
echo '%domain\ admins@example.com ALL=(ALL:ALL) ALL' > /etc/sudoers.d/example.com # Allow all domain users to act as root in high-trust environments
ssh-keyscan localhost | ssh-keygen -lf - # Take a record of the SSH keys for secure login
realm join -v -U <your unqualified domain user name> example.com # J
@nzbart
nzbart / app.R
Last active March 18, 2020 07:31
New Zealand coronavirus/COVID-19 case chart as Shiny app. Published at https://bartj.shinyapps.io/covid19/.
library(shiny)
library(tidyverse)
library(lubridate)
library(plotly)
library(scales)
ui <- shiny::fillPage(
titlePanel("Coronavirus in NZ"),
@nzbart
nzbart / Directory.Build.props
Last active February 26, 2020 23:16
Disable Roslyn analysis for debug builds, but keep real-time analysis in IDEs and release mode builds. Simply put this file in the project root.
<Project>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
</PropertyGroup>
</Project>