Skip to content

Instantly share code, notes, and snippets.


Michael Kropat mkropat

Block or report user

Report or block mkropat

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View traverse-level-order.js
function traverseLevelOrder(thing, predicate, maxDepth=20) {
function traverse(thing, predicate, targetDepth, depth=0) {
if (targetDepth !== depth) {
for (const key in thing) {
const val = traverse(thing[key], predicate, targetDepth, depth + 1);
if (val) {
return val;
echo "| Name | Partition | Size (kB) | Path | Type |"
echo "|------|-----------|-----------|------|------|"
for d in /dev/block/bootdevice/by-name/*; do
name=$(basename -- "$d")
device=$(basename "$(readlink -- "$d")")
read -r _ fsmount fstype _ <<EOF
View Extract-Roms.ps1
$ErrorActionPreference = 'Stop'
function Get-RomFromArchive {
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
[string] $Path,
mkropat / com.codetinkerer.caffeinate.plist
Created Jun 14, 2019
Disable display power down during working hours
View com.codetinkerer.caffeinate.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
View json-array-gotcha.ps1
echo '[1, 2, 3]' | ConvertFrom-Json | measure
# Count: 1
(echo '[1, 2, 3]' | ConvertFrom-Json) | measure
# Count: 3
echo '[1, 2, 3]' | ConvertFrom-Json | ConvertTo-Json
# "value": [
# 1,
View AddProgramToAppPath.ps1
#Requires -RunAsAdministrator
[string] $Name
$ErrorActionPreference = 'Stop'
if (-not [System.IO.Path]::GetExtension($Name)) {
View git-go
OPTIONS_SPEC='git go [options] [branch]
b,branch create and checkout a new branch
. "$(git --exec-path)/git-sh-setup"
sed -nE 's/^\s*(\S+)\s+\S+\s+(\S+)\s+\[([^]]*)\]\s+"(\S+)\s+(\S+)[^"]*"\s+(\S+)\s+(\S+)\s+"([^"]*)"\s+"([^"]*)".*/\1\n\2\n\3\n\4\n\5\n\6\n\7\n\8\n\9\x00/p' |
while IFS=$'\n' read -r -d $'\0' ip user timestamp method url status bytes referrer useragent; do
echo $method $url;
#while IFS= read -r line; do
# #mapfile -t parts < <(printf '%s\n' "$line" | IFS=$'\n' xargs -n1 printf '%s\n')
# mapfile -t parts < <(printf '%s\n' "$line" | sed -nE 's/^\s*(\S+)\s+\S+\s+(\S+)\s+\[([^]]*)\]\s+"(\S+)\s+(\S+)[^"]*"\s+(\S+)\s+(\S+)\s+"([^"]*)"\s+"([^"]*)".*/\1\n\2\n\3\n\4\n\5\n\6\n\7\n\8\n\9/p')
View array-equality-test.ps1
PS > [bool] ($null -eq $null)
True # Makes sense
PS > [bool] (@($null) -eq $null)
False # As expected, but not for the reason you think
PS > [bool] (@($null, $null) -eq $null)
True # What?!?
PS > [bool] (-null -eq @($null, $null))
False # Much better, hence "$null should be on the left side of equality comparisons"
View SameSiteCookieMiddleware.cs
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
public enum SameSitePolicy
You can’t perform that action at this time.