This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// only covers a small subset of the Map api! | |
// haven't debugged yet! | |
class BigMap { | |
constructor(iterable) { | |
if(iterable) throw new Error("haven't implemented construction with iterable yet"); | |
this._maps = [new Map()]; | |
this._perMapSizeLimit = 14000000; | |
this.size = 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given a large input image, this script generates map tiles of 256*256px | |
// at power-of-2 zoom levels. It's not super efficient or anything, just a | |
// quickly hacked together script. | |
//Use the tiles in leaflet.js like this: | |
/* | |
<div id='map' style='height:100%;'></div> | |
<script> | |
var map = L.map('map', { | |
attributionControl: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Notes: we need the `sourceTabUrl &&` before the URL check because chromebooks make weird requests that don't come from "real" tabs. | |
let accessHeaders = new Map(); | |
let tabIdToUrlMap = new Map(); | |
let requestListener = function (details) { | |
const accessControlRequestHeader = details.requestHeaders.find(elem => elem.name.toLowerCase() === "access-control-request-headers"); | |
if(accessControlRequestHeader) { | |
accessHeaders.set(details.requestId, accessControlRequestHeader.value); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function matches all non-ASCII characters after splitting the string in a "unicode-safe" way (using `[...str]`). | |
// It then splits each unicode character up into its code-points, and gets the escape code for each, and then joins all | |
// all the ASCII characters and Unicode escapes into one string. | |
function escapeUnicode(str) { | |
return [...str].map(c => /^[\x00-\x7F]$/.test(c) ? c : c.split("").map(a => "\\u" + a.charCodeAt().toString(16).padStart(4, "0")).join("")).join(""); | |
} | |
// Based on discussion in this thread: https://gist.github.com/mathiasbynens/1243213 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Put this in your HTML to load the `Vips` global: <script src="https://cdn.jsdelivr.net/npm/wasm-vips@0.0.2/lib/vips.js"></script> | |
const vips = await Vips(); | |
async function resizeAndCenterCrop(blob, resizeType="cubic", size=224) { | |
// resize types available: cubic, linear, lanczos2, lanczos3, nearest, mitchell | |
let im1 = vips.Image.newFromBuffer(await blob.arrayBuffer()); | |
// Resize so smallest side is `size` px: | |
const scale = 224 / Math.min(im1.height, im1.width); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function() { | |
let request = require("request-promise"); | |
let stopFlag; | |
async function start() { | |
if(!this.oncomment) { | |
console.error("You must attach an oncomment handler (onerror handler is optional)."); | |
return; | |
} |
NewerOlder