Skip to content

Instantly share code, notes, and snippets.

Avatar
👋

Matt DesLauriers mattdesl

👋
View GitHub Profile
View README.md

NFT Statement

Feb 26, 2021

I have decided to release a small set of single-edition NFTs on OpenSea.

I plan to place 100% of direct proceeds from the first sale toward the Bounty for More Eco-Friendly NFTs being developed by Artnome and GitCoin, and 25% of direct proceeds of each of the subsequent 9 artworks in this series toward the same fund.

You can bid/purchase/view the first minted artwork here, and the full series here. At the time of writing, I have only placed 1 artwork on auction, but will place the other 9 in the coming days/weeks.

View malloc.js
// get a pointer to 16 bytes of WASM memory
const byteLength = 16;
const pointer = Module._malloc(byteLength);
// e.g. let's set all values to 0xff (255)
for (let i = 0; i < byteLength; i++) {
const idx = pointer + i;
Module.HEAPU8[idx] = 0xff;
}
View malloc.js
let buffer = new Uint8Array(2048);
let index = 0;
let blocked = [];
// allocate a pointer with given byteLength
function malloc (byteLength) {
let size = alignToBlockSize(byteLength);
let index = findFreeIndex(size);
// no free blocks in memory, gotta expand...
@mattdesl
mattdesl / createFile.js
Last active Feb 16, 2021
simple expandable in-memory file utility, inspired by Emscripten's FS
View createFile.js
export default function createFile(initialCapacity = 256) {
let cursor = 0;
let usedBytes = 0;
let contents = new Uint8Array(initialCapacity);
return {
contents: function () {
return contents.slice(0, usedBytes);
},
seek: function (offset) {
// offset in bytes
View encode.js
// setup a new encoder with a write callback
const enc = Module.create_encoder(writeEncodedData);
// do some encoding
// ...
// dispose encoder
Module.free_encoder(enc);
// The write callback
View lib.cpp
using namespace emscripten;
// The struct will hold encoder instance data
typedef struct MyEncoder {
// The JavaScript callback that writes encoded data to output
std::function<int(uint8_t *data, uint32_t size)> callback;
// other instance data ...
uint32_t width;
uint32_t height;
View lib.cpp
void encode (uintptr_t rgb_buffer_ptr)
{
uint8_t* rgb = reinterpret_cast<uint8_t*>(rgb_buffer_ptr);
// now you can do something with the rgb data...
}
@mattdesl
mattdesl / bash.sh
Created Feb 14, 2021
(unix) one-line convert all TIFs in folder to high quality JPG
View bash.sh
for i in *.tif; do sips -s format jpeg -s formatOptions best $i --out ${i%tif}converted.jpg;done
View README.md

test-avc

Test AVC codec quality problems with WebCodecs.

To run, git clone this gist, then serve it locally in Chrome Canary with WebCodecs enabled.

git clone https://gist.github.com/a682dbe63efa074514a500724d712955.git test-avc
@mattdesl
mattdesl / sketch.js
Last active Dec 3, 2020
h264-mp4-encoder + canvas-sketch = in-browser MP4 generation
View sketch.js
// npm canvas-sketch-cli -g
// canvas-sketch sketch.js --open
const canvasSketch = require('canvas-sketch');
const H264 = require('h264-mp4-encoder');
const { lerp } = require("canvas-sketch-util/math");
const settings = {
duration: 4,
dimensions: [1024, 1024],