Skip to content

Instantly share code, notes, and snippets.

View amishshah's full-sized avatar
🐼

Amish Shah amishshah

🐼
View GitHub Profile
@amishshah
amishshah / discordjs.md
Created October 22, 2021 22:36
tl;dr i'm stepping down as owner of discord.js!

Hello! I'm Amish (also known as hydrabolt), and I am the creator of discord.js.

I created discord.js as a hobby/learning project for myself in August 2015 while I was still a teenager in school.

More than 6 years later, discord.js has become more popular than I could ever imagine, and I cannot express how grateful I am to the other contributors and the community for this amazing experience.

A few of my favourite highlights include:

  • The countless voice rewrites (I think we're done with that now 😉)
  • The April Fools' traditions
@amishshah
amishshah / ogg-containers.md
Last active June 12, 2023 21:16
A guide to the Ogg container format for demuxing opus audio

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.
@amishshah
amishshah / har-extract.js
Created February 12, 2017 16:14
Rough script to extract images from HTTP Archive (HAR) files
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 March 21, 2021 12:19
Allows for writing a Node.js object stream to a non-object format and then later parsing it.
'use strict';
const { Transform } = require('stream');
exports.Serialiser = class Serialiser extends Transform {
constructor(options) {
super({ writableObjectMode: true, ...options });
}
_transform(chunk, encoding, callback) {

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 December 1, 2017 14:43
builds omxplayer on rpi3 stretch lite
#!/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

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: