Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mreinstein's full-sized avatar
💥
ABC always be codin!

Michael Reinstein mreinstein

💥
ABC always be codin!
View GitHub Profile
@mreinstein
mreinstein / index.md
Created August 2, 2017 17:15
determine the TCP port on which a node.js program listens

Find the pid of the running process if you don't know it:

$ ps ax | grep node
1012 ?        Ssl    0:03 node /usr/bin/signalhub listen -p 8000

In this case we're running a node program and it's pid is 1012

@mreinstein
mreinstein / transform-javascript.js
Created February 18, 2020 10:40
parse javascript from stdin as an AST and remove specific functions by name
import escodegen from 'escodegen'
import esprima from 'esprima'
import estraverse from 'estraverse'
let src = ''
process.stdin.on('data', function (chunk) {
src += chunk
})
function createDiscreteProblem () {
return {
allAssignments: [ ],
variables: { },
constraints: [ ]
}
}
@mreinstein
mreinstein / resize-tiled-map.js
Created June 19, 2020 00:36
resize the tileset used by a tiled map, preserving the col, row locations
let level = require('./level.js')
// given a tiled level that references a tileset of certain dimensions, update to a tileset of different dimensions
let idx = -1
const locations = [ ]
do {
@mreinstein
mreinstein / downscale.sh
Created February 3, 2021 04:25
downscale images
brew install imagemagick
mogrify -resize 50% -format png *
brew install ffmpeg --with-fdk-aac
ffmpeg -i movie.avi movie.mp4
@mreinstein
mreinstein / dimensions.sh
Created April 4, 2022 03:22
ffmpeg - determine video dimensions
ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 input.mp4
@mreinstein
mreinstein / resize.sh
Created April 4, 2022 03:23
ffmpeg - resize video
# resize
ffmpeg -i input.mp4 -vf scale=1920:1080 output.mp4
# resize with high quality
ffmpeg -i input.mp4 -vf scale=1920:1080 -preset slow -crf 18 output.mp4
@mreinstein
mreinstein / hls.sh
Created April 4, 2022 03:24
ffmpeg - generate hls videos from an input video
# how to generate hls outputs
# from https://ottverse.com/hls-packaging-using-ffmpeg-live-vod/
# had to make a slight adjustment for zsh by wrapping quotes around the -map params, as explained in https://stackoverflow.com/a/60290103/1927767
ffmpeg -i input.mp4 \
-filter_complex \
"[0:v]split=3[v1][v2][v3]; \
[v1]copy[v1out]; [v2]scale=w=960:h=540[v2out]; [v3]scale=w=480:h=270[v3out]" \
-map "[v1out]" -c:v:0 libx264 -x264-params "nal-hrd=cbr:force-cfr=1" -b:v:0 5M -maxrate:v:0 5M -minrate:v:0 5M -bufsize:v:0 10M -preset slow -g 48 -sc_threshold 0 -keyint_min 48 \
-map "[v2out]" -c:v:1 libx264 -x264-params "nal-hrd=cbr:force-cfr=1" -b:v:1 3M -maxrate:v:1 3M -minrate:v:1 3M -bufsize:v:1 3M -preset slow -g 48 -sc_threshold 0 -keyint_min 48 \
@mreinstein
mreinstein / consolidate-media.md
Last active May 16, 2022 03:49
script to consolidate and clean up media on my computer

media-consolidator

script to consolidate and clean up media on my computer

# copy all known places where photos exist to input/
# preserve metadata when doing the copy (modification timestamps, etc.)
cp -rp ~/Pictures/* input/
cp -rp ~/Documents/Photos/* input/