Skip to content

Instantly share code, notes, and snippets.

View JTBrinkmann's full-sized avatar

Jan-T. Brinkmann JTBrinkmann

  • Stralsund, Germany
View GitHub Profile
@JTBrinkmann
JTBrinkmann / Tree.tsx
Last active October 20, 2021 13:58
Chakra UI component to render a javascript object, similar to console.log in browsers' devtools
import { ChevronDownIcon, ChevronRightIcon } from "@chakra-ui/icons"
import { Box, chakra, Icon, useDisclosure } from "@chakra-ui/react"
import { useMemo } from "react"
export const json = (obj: any) =>
obj === undefined ? "undefined" : JSON.stringify(obj, null, 2)
export const closeBrackets = (str: string) =>
str.replace(
/[\(\[\{]+$/,
@JTBrinkmann
JTBrinkmann / cwrsync.ps1
Last active March 15, 2023 13:57
wrapper to make cwrsync and DeltaCopy's rsync work, while allowing to have a different ssh.exe in your PATH
rsync.exe --rsh="/bin/ssh" @args
# tested 2023-03-15, SSH keys should also work out of the box
# for using a different port, do e.g. `--rsh="/bin/ssh -p 1234"`
@JTBrinkmann
JTBrinkmann / searchParamsToJson.js
Last active November 1, 2021 10:03
javascript parse URL search params or FormData as an object
// convert WITHOUT considering multiple values
// every value will be a string
const parseSearchParams = (data) => [...new URLSearchParams(data).entries()].reduce((acc,[key, val]) => (acc[key]=val,acc), {})
// convert WITH considering multiple values
// every value will be a either a string or an array of strings
const parseSearchParamsMultiple = (data) => [...new URLSearchParams(data)].reduce((acc,[key, val]) => (acc[key] = acc[key]?[].concat(acc[key], val) : val, acc), {})
// test cases
const testSingle = "a=1&b=2&c=3"
@JTBrinkmann
JTBrinkmann / destruct-alternatives.sh
Last active June 24, 2024 23:13
bash destructuring assignment for arrays
#!/bin/bash
## Alternative Versions
# only allows space separated variable name list
# example: destruct a b c = arr
destruct() {
for ((i=1;i < $#-1; ++i)) do
local value_adress="${!#}[$i-1]"
declare -g "${!i}=${!value_adress}"
done
@JTBrinkmann
JTBrinkmann / youtube-anon-playlist-creator.html
Created June 6, 2020 20:39
very small webapp to create an anonymous youtube playlist from a few videos
<!DOCTYPE html>
<body style="font-family: sans-serif;">
<p>
<label>
Youtube URLs:<br>
<textarea id="input" style="box-sizing: content-box; width: 100%; min-height: 8em; line-height: 1.4em; padding: 0.2em"></textarea>
</label>
</p>
<p>
<label>
@JTBrinkmann
JTBrinkmann / youtube-lazyload-embed-generator.html
Created June 4, 2020 11:28
small web-tool to create embed code for lazy loaded youtube embeds
<!DOCTYPE html>
<body style="font-family: sans-serif">
<form>
<label>
Video-URL or ID:
<input id="videourl" value="3q_iqrvnC_4" style="width: 40em" />
</label>
<p id="warning" style="visibility: hidden; background: yellow; font-weight: bold;">
Warning: the extracted video id seems unusual
</p>
javascript:$('body').css('color-adjust','exact');fetch('/css/bootstrap.min.css').then(r=>r.text()).then(b => { b = b.replace(/@media\s+print\s*\{[\s\S]*?\}\s*\}/g, '').replace(/url\(\./g,'url(/css/.'); $a = $('link[href="/css/bootstrap.min.css"]').attr('media', 'none'); $('<style>').text(b).insertAfter($a) })
param (
[string] $inFilePath,
[string] $outFilePath = $false
)
# older PowerPoint versions don't support exporting to MP4 (e.g. 2010)
# use WMV as fallback and if necessary convert via ffmpeg (not part of this script)
if ([Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::ppSaveAsMP4) {
$outExt = "mp4"
$outExtType = [Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType]::ppSaveAsMP4
$inputs = ls -R -F *.mp4
$i = 0
for ($input in $inputs) {
Write-Progress -Activity "Converting Videos" -Status "$(++$i / $inputs.Length)% $($input.Name)" -PercentComplete $($i / $inputs.Length)
$output = Join-Path "..\compressed" ($_ | Resolve-Path -Relative)
if (Test-Path $output) {
echo "already exists: $output"
} else {
mkdir ($output | Split-Path)
ffmpeg -hide_banner -i $input -movflags faststart -r 25 -vf scale=-1:720 -tune stillimage $output