Skip to content

Instantly share code, notes, and snippets.

Avatar
🐼

Amish Shah amishshah

🐼
View GitHub Profile
@amishshah
amishshah / har-extract.js
Created Feb 12, 2017
Rough script to extract images from HTTP Archive (HAR) files
View har-extract.js
const fs = require('fs');
const file = JSON.parse(fs.readFileSync('./dump.har')).log;
const targetMimeType = 'image/jpeg';
let count = 1;
for (const entry of file.entries) {
if (entry.response.content.mimeType === targetMimeType) {
// ensure output directory exists before running!
fs.writeFileSync(`output/${count}.png`, new Buffer(entry.response.content.text, 'base64'), 'binary');
count++;
@amishshah
amishshah / object-stream-marshaller.js
Created Mar 21, 2021
Allows for writing a Node.js object stream to a non-object format and then later parsing it.
View object-stream-marshaller.js
'use strict';
const { Transform } = require('stream');
exports.Serialiser = class Serialiser extends Transform {
constructor(options) {
super({ writableObjectMode: true, ...options });
}
_transform(chunk, encoding, callback) {
@amishshah
amishshah / ogg-containers.md
Last active Jan 20, 2020
A guide to the Ogg container format for demuxing opus audio
View ogg-containers.md

You take a stream/buffer of binary data. The start of your data is a "Page", which has a header followed by data.

Header

You need to read the following data from the header (see https://xiph.org/ogg/doc/framing.html for more detail)

  • capture_pattern - bytes 0 to 3, must read OggS
  • stream_structure_version - byte 4, must be 0
  • header_type_flag - byte 5, a bitflag that tells you metadata about the page (is it a new packet? is a packet continued here? is it the first/last page of the stream?)
  • absolute granule position - bytes 6 to 13, not needed unless you want seeking
  • stream serial number - bytes 14 to 17, a serial number given to each stream contained in the Ogg file. This is important for playing Ogg files that contain other streams, such as video or cover art. You need to identify and only bother parsing the Opus stream.
View keybase.md

Keybase proof

I hereby claim:

  • I am amishshah on github.
  • I am hydrabolt (https://keybase.io/hydrabolt) on keybase.
  • I have a public key whose fingerprint is 7355 4FA4 E9CA 9D37 2735 CA0F 57FF CB08 F5A4 2963

To claim this, I am signing this object:

@amishshah
amishshah / omxplayer_build.sh
Last active Dec 1, 2017
builds omxplayer on rpi3 stretch lite
View omxplayer_build.sh
#!/bin/bash
apt-get update
apt-get install -y git libasound2-dev libavutil-dev libpcre3-dev libboost-dev
git clone https://github.com/popcornmix/omxplayer.git
cd omxplayer
./prepare-native-raspbian.sh
make ffmpeg
make -j$(nproc)
sudo make install
View keybase.md

Keybase proof

I hereby claim:

  • I am hydrabolt on github.
  • I am hydrabolt (https://keybase.io/hydrabolt) on keybase.
  • I have a public key whose fingerprint is 7355 4FA4 E9CA 9D37 2735 CA0F 57FF CB08 F5A4 2963

To claim this, I am signing this object: