Skip to content

Instantly share code, notes, and snippets.

View mkropat's full-sized avatar
📚
Learning

Michael Kropat mkropat

📚
Learning
View GitHub Profile
objs = new Set
nameToObj = new Map
function t(obj) {
if (!obj || objs.has(obj) || typeof obj !== 'object') { return }
if (obj.nodeName === 'IFRAME') { return } // iframe descendants can cause security errors
objs.add(obj)
let proto = Object.getPrototypeOf(obj)
let name = (obj.constructor && obj.constructor.name) || (proto && proto.constructor && proto.constructor.name)
if (!nameToObj.has(name)) { nameToObj.set(name, []) }
nameToObj.get(name).push(obj)
" Pattern 1:
"
" * Operate over a whole file: :call ConvertFile()
" * Or operate over a selection: :'<,'>call ConvertLine()
" * Supports the same :s// and normal commands you regularly use in Vim
" * So minimal Vim Script knowledge needed
function! ConvertFile()
%global/^/call ConvertLine()
endfunction
// 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));
@mkropat
mkropat / store.js
Last active September 5, 2022 12:59
// Moved to: https://github.com/mkropat/todomvc-tagsjs/blob/main/lib/store.js
// 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));
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
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;
#!/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
$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 June 14, 2019 21:04
Disable display power down during working hours
<?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>