Skip to content

Instantly share code, notes, and snippets.

Avatar
🛠️
Tinkering

Michael Kropat mkropat

🛠️
Tinkering
View GitHub Profile
View store.js
class AggregateError extends Error {
constructor(message, errors) {
super(`${message}:\n\n${errors.map(e => e.message).join('\n')}`)
this.errors = errors
}
}
export const store = window.store = {
_listeners: [],
_prevState: {},
View jsizes.c
// gcc -I$JAVA_HOME/include -I$JAVA_HOME/include/linux jsizes.c -o jsizes && ./jsizes
#include <stdio.h>
#include <jni.h>
int main() {
printf("jboolean %li\n", sizeof (jboolean));
printf("jbyte %li\n", sizeof (jbyte));
printf("jchar %li\n", sizeof (jchar));
printf("jshort %li\n", sizeof (jshort));
View encrypt.ps1
function Compute-Sha256($Str) {
$sha256 = New-Object System.Security.Cryptography.SHA256Managed
$sha256.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($Str))
}
function Get-RandomBytes($Size) {
$rng = New-Object System.Security.Cryptography.RNGCryptoServiceProvider
$bytes = [System.Byte[]]::new($Size)
$rng.GetBytes($bytes)
$bytes
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;
}
}
return;
View dump-partitions.sh
#!/bin/sh
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 {
[CmdletBinding()]
param(
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]
[Alias("PsPath")]
[string] $Path,
[Parameter(Mandatory=$True)]
@mkropat
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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.codetinkerer.caffeinate.plist</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/caffeinate</string>
<string>-d</string>
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
[CmdletBinding()]
param(
[string] $Name
)
$ErrorActionPreference = 'Stop'
if (-not [System.IO.Path]::GetExtension($Name)) {
View git-go
#!/bin/sh
SUBDIRECTORY_OK=1
OPTIONS_SPEC='git go [options] [branch]
--
b,branch create and checkout a new branch
'
. "$(git --exec-path)/git-sh-setup"