Skip to content

Instantly share code, notes, and snippets.

View HashemKhalifa's full-sized avatar

Hashem Khalifa HashemKhalifa

  • Munich, Germany
View GitHub Profile
@HashemKhalifa
HashemKhalifa / array_iteration_thoughts.md
Created January 13, 2017 16:36 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@HashemKhalifa
HashemKhalifa / destructuring.js
Created March 2, 2017 07:08 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
@HashemKhalifa
HashemKhalifa / flac-to-alac-convert.sh
Created August 31, 2022 12:00 — forked from jj1bdx/flac-to-alac-convert.sh
Convert FLAC to ALAC in batch
#!/bin/sh
# https://sound.stackexchange.com/questions/26633/free-batch-conversion-from-flac-to-apple-lossless-alac
# https://stackoverflow.com/questions/55429909/could-not-find-tag-for-codec-h264-in-stream-0-codec-ffmpeg-flac-to-alac-conver
for name in *.flac; do \
ffmpeg -nostdin -i "$name" -c:a alac -c:v copy "${name%.*}.m4a" && \
ffmpeg -nostdin -i "$name" -vf "crop=((in_w/2)*2):((in_h/2)*2)" \
"${name/%flac/jpg}" && \
AtomicParsley "${name/%flac/m4a}" --artwork "${name/%flac/jpg}" --overWrite; \
done