Skip to content

Instantly share code, notes, and snippets.

@jrwarwick
jrwarwick / Microsoft.PowerShellISE_Profile.ps1
Created February 25, 2020 18:28
Microsoft.PowerShellISE_Profile.ps1
## $env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShellISE_Profile.ps1
# Very low external dependencies edition
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('Run with -Verbose',{ Invoke-Expression `
-Command ". '$($psISE.CurrentFile.FullPath)' -Verbose" }, `
'Ctrl+F5') | Out-Null
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('Run with -Debug', { Invoke-Expression `
-Command ". '$($psISE.CurrentFile.FullPath)' -Debug" }, `
'Ctrl+F6') | Out-Null
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add('Launch Script Analyzer',{ Invoke-Expression `
@jrwarwick
jrwarwick / ps_ise_save_console_text.ps1
Created December 10, 2019 16:43
PowerShell ISE One-Liner: save Console pane text to file
#Maybe you just finished executing a bunch of stuff in the ISE script window and want to save the entire output
#maybe for a deployment log or something. Just drop this in scripting window, highlight, and execute selection.
#Could use this as an sort of alternative to Start-Transcript, too, but only in ISE execution situation.
$psise.CurrentPowerShellTab.ConsolePane.Text | Set-Content -Path $env:USERPROFILE\Downloads\ps_ise_execution_log_$((get-date).tostring("yyyyMMdd")).txt
@jrwarwick
jrwarwick / README.md
Last active October 16, 2019 06:13 — forked from insin/README.md
Extract Minecraft music

Extract Minecraft music (Windows-centric easy-cheezy edition)

As of 1.8, assets are stored by hash, which makes it fiddly to listen to Minecraft's amazing ambient soundtrack outside the game.

This script can be used to copy music files to appopriately-named and organised .ogg files for easier listening.

0. If you happen to have PowerShell 3.0, you might be able to just save and execute extract_mc_music.ps1 and then skip to step 5

1. Install Node.js. Actually, you don't even have to "install". You can just download the stand-alone zip archived version, extract it, and start a CMD shell in the subdirectory with node.exe in it.

2. Save extract_mc_music.js to your freshly extracted node directory.

@jrwarwick
jrwarwick / apache_httpd_access_log_digest.sh
Created September 27, 2019 19:04
Apache httpd access_log digest in CSV, one-liner
egrep -hv '^::1 - -|"-" 408 - "-" "-"$' /var/log/httpd/access_log* | sed -e 's#\(https\?://[a-zA-Z0-9.\-]\+\)/##' | awk -F'[ "]+' '{print $4,$5","$3","$1","$6","$7}' | sed 's/\?/,/' | sed -e 's/^\[/"/' -e 's/\],/",/' | sed 's/:/","/' | egrep -hv '.png$|.jpg$|.gif$|.css$|.js$|.ico$' | egrep -hv 'OPTIONS,/fv/$|OPTIONS,HTTP/1.1$' | sort -u > /tmp/httpd_access_log_$(date +%Y%m%d).csv
@jrwarwick
jrwarwick / httpsminiserver.py
Last active August 6, 2019 21:11
HTTPS mini server will serve the current directory listing as downloadable files after auto-generating a self-signed SSL cert
#!/usr/bin/env python
# Based on the brilliant work of Jorge which I found here:
# https://jorge.fbarr.net/2017/06/11/simplehttpserver-with-ssl/
# He truly honors KISS principles. I just needed a little more automagicalness
# at the cost of a little more complexity and reduced portability.
# Oriented around the python 2.7 and openssl 1.1.1 world that some UNIX boxen are living in.
# Should handle even Chrome's more stringent Subject AltName requirements.
# Extra handy if started in a GNU screen session thus:
# screen -S httpsMiniServer /usr/local/httpsminiserver/httpsminiserver.py
import os.path
@jrwarwick
jrwarwick / generate_quicksql_for_existing_tables.sql
Created June 13, 2019 22:49
Generate Oracle QuickSQL from all visible tables
-- Quick, dirty, and incomplete. Look to dgielis/model_to_quicksql.sql for more power
select table_name||chr(10)||listagg(' '||column_name||' '
||case data_type
when 'VARCHAR2' then 'vc'||to_char(data_length)
when 'NUMBER' then 'num'
when 'INTEGER' then 'int'
when 'DATE' then 'date'
when 'INTEGER' then 'int'
END,chr(10)) within group (order by column_id) quicksql
from all_tab_cols
@jrwarwick
jrwarwick / generate_glados_utterances.sh
Last active May 31, 2019 23:39
GLADOS-like voice synth
#!/bin/bash
# rapidly rattle off a bunch of eerily familiar utterances
# Credit to https://a3nm.net/blog/glados_espeak.html
while read LINE </dev/tty ; do
TITLE=$( echo $LINE | sed 's/[^a-zA-Z0-9 ]//g; s/ \+/_/g; s/_the_//g; s/_to_//g;' )
echo $LINE | for a in `cat`; do
V=$(((($RANDOM) % 100) - 50)); echo -n "<prosody pitch=\"+$V\">$a</prosody> " |
sed 's/+-/-/' ;
done | espeak -ven+f3 -m --stdout -p 55 -s 150 | oggenc -q1 - > GLADOS_${TITLE}.ogg
done
@jrwarwick
jrwarwick / der_to_pfx_conversion.sh
Created April 3, 2019 17:18
PFX/PKCS12 SSH Certificate renewal preparation from DER
#!/bin/sh
#Scenario: some issuer reissues to you a renewed certificate in DER/x509 format,
#but you need it in PFX/PKCS12 format (perhaps to utilize in some Windows PowerShell scripts).
#quick sequence to perform the conversion and sanity check.
#To extract the private key embedded in the (soon to expire) PFX:
openssl pkcs12 -in old_about_to_expire.pfx -nocerts -out extracted_private_key.pem
#To sanity check the incoming renewed cert:
openssl x509 -inform der -in renewed_certificate_as_issued.der -noout -text | grep -v '\([a-z0-9]\{2\}:\)\{10,\}'
@jrwarwick
jrwarwick / counting_and_multiplying_race.ps1
Created March 13, 2019 14:46
Demo: Computers are Fast at Counting and Simple Math
$multiple = 2
$currentNumber = 1
while ($currentNumber -lt 562949953421310) {
$currentNumber = $currentNumber * $multiple
$currentNumber
}
$vox = New-Object -com SAPI.spvoice
$vox.speak("Sorry, too late. I have already reached $($currentNumber). As you can see, computers really are amazingly, blazingly fast.")
@jrwarwick
jrwarwick / windows_print_log_search.ps1
Last active January 25, 2019 23:30
When you need to find out when or if a user sent a print job through the print server.
#!PowerShell
# Assumes print logging is turned on. This is usually the case on print servers,
# yet usually not the case on desktop workstations.
$searchstring = Read-Host -Prompt 'Target username'
$WinEventXMLFilter = '
<QueryList><Query Id="0" Path="Microsoft-Windows-PrintService/Operational">
<Select Path="Microsoft-Windows-PrintService/Operational">*[System[(Level=4 or Level=0) and (EventID=307)]]</Select>
</Query></QueryList>'
$PrintEvents = Get-WinEvent -FilterXml $WinEventXMLFilter -Computer $(Read-Host -prompt 'Print Server computername')