Skip to content

Instantly share code, notes, and snippets.

@josephrocca
josephrocca / mute-all-bsky-likers-by-post-url.js
Last active December 9, 2024 04:22
Mute all likers of a specific post, based on the post's URL - bookmarklet for bluesky (bsky.app) - you can use https://chriszarate.github.io/bookmarkleter/ to turn it into a bookmarklet
// You can turn this code into a bookmarklet by pasting all the code here into this bookmarklet maker: https://chriszarate.github.io/bookmarkleter/
// Then just visit the post URL that you want to use it on, and click the bookmarklet.
// Or just manually copy-paste all of the code in this file into the browser console while on the bsky.app site (use Ctrl+Shift+J to open browser console in Chrome)
// CAUTION(!!!): You should be vary wary of running random code you find on the internet within authenticated applications like Bluesky, since the code could steal your login details.
if(confirm("This will mute everyone who liked the post you're currently viewing. Make sure you've clicked into the post, so the post URL is in your browser address bar. You can check your browser console with Ctrl+Shift+J for progress/errors if needed.")) {
muteAllLikersByPostUrl(window.location.href);
}
async function muteAllLikersByPostUrl(postUrl) {
// Extract author and post id from URL:
let postAuthorIdentifier = postUrl.matc
@josephrocca
josephrocca / instructions.md
Last active October 14, 2024 05:14
Instructions for making a custom build of the `deno` executable that supports heap memory limits on Web Workers via an environment variable.

Here are instructions for making a custom build of the deno executable that supports heap memory limits on web workers via an environment variable called WEB_WORKER_HEAP_LIMIT_BYTES.

Note that, unfortunately, this does not limit "Large Object Space" allocations, since V8 makes those allocations outside the heap. This includes e.g. large ArrayBuffers, Typed Arrays, and potentially other stuff. I've opened an issue about this here: denoland/deno#26202

Clone Repo:

git clone --recurse-submodules --branch v2.0.0 https://github.com/denoland/deno.git
cd deno
# on local machine
git clone https://github.com/comfyanonymous/ComfyUI
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Manager.git
cd ../
# start docker
docker run --name comfyui -p 8188:8188 -it --rm --gpus all -v $PWD:/workspace pytorch/pytorch:2.2.1-cuda12.1-cudnn8-devel bash
apt-get update
apt-get install wget git libgl1 libglib2.0-0 -y
@josephrocca
josephrocca / removeExifFromJpeg.js
Created August 18, 2023 11:50
Remove EXIF data from JPEG using JavaScript - simple and extremely fast
// Code mostly written by GPT-4. Works well for me, but not extensively tested (e.g. on old or weird jpeg files)
function removeExifFromJpeg(arrayBuffer) {
let view = new DataView(arrayBuffer);
// Check if it's a JPEG file
if (view.getUint16(0, false) !== 0xFFD8) {
throw new Error("Not a valid JPEG");
}
let position = 2; // Start after the SOI marker
@josephrocca
josephrocca / e5-large-v2.js
Last active August 14, 2024 11:38
e5-large-v2 text embedding model in JavaScript using Transformers.js
// See the comments at the end for a model that does much better than e5-large-v2 while being a third of the size.
let { pipeline } = await import('https://cdn.jsdelivr.net/npm/@xenova/transformers@2.7.0');
let extractor = await pipeline('feature-extraction', 'Xenova/e5-large-v2');
// Note: If you're just comparing "passages" with one another, then just prepend "passage: " to all texts. Only use "query: " if the text is a short "search query" like in the above example.
let passage1 = await extractor(`passage: The Shawshank Redemption is a true masterpiece of cinema.`, { pooling: 'mean', normalize: true });
let passage2 = await extractor(`passage: The film should not be exposed to sunlight when removing it from the wrapper. Otherwise your movie will come out bad.`, { pooling: 'mean', normalize: true });
let query = await extractor(`query: movie review`, { pooling: 'mean', normalize: true });
// This is a version of this file: https://w3c.github.io/webcodecs/samples/capture-to-file/webm-writer2.js
// With these fixed applied: https://github.com/w3c/webcodecs/issues/332#issuecomment-1077442192
/**
* A tool for presenting an ArrayBuffer as a stream for writing some simple data
* types.
*
* By Nicholas Sherlock, with updates from jimbankoski
*
* - make it work off frames with timestamps from webcodecs
@josephrocca
josephrocca / createCanvasFromRGBAData.js
Created December 1, 2022 10:52
RGBA data to canvas - create a canvas from RGB data
function createCanvasFromRGBAData(data, width, height) {
// `data` should look something like [[123,32,40,255], [3,233,42,120], ...]
if(width*height !== data.length) throw new Error("width*height should equal data.length");
let canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
let ctx = canvas.getContext("2d");
let imgData = ctx.createImageData(width, height);
for(let i = 0; i < data.length; i++) {
imgData.data[i*4+0] = data[i][0];
@josephrocca
josephrocca / notebook.ipynb
Last active November 14, 2022 00:49
lyra-v2-soundstream split quantizer into its two subgraphs.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@josephrocca
josephrocca / onnx-runtime-python-inference.ipynb
Last active October 30, 2022 16:53
onnx-runtime-python-inference.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@josephrocca
josephrocca / aaa_usage.js
Created October 29, 2022 07:33
AWS S3 (v3) working in Deno
import * as AWS from "./aws_sdk_client_s3_v3.198.0-es.js";
let s3 = new AWS.S3({
region: "YOUR_REGION",
endpoint: "YOUR_ENDPOINT_URL_IF_NECCESSARY",
credentials: {
accessKeyId: "YOUR_ACCESS_KEY",
secretAccessKey: "YOUR_SECRET",
},
});