Skip to content

Instantly share code, notes, and snippets.

/*
The MIT License (MIT)
Copyright (c) 2023 - 2023 Matias Affolter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
/*
The MIT License (MIT)
Copyright (c) 2023 Matias Affolter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@vipertechofficial
vipertechofficial / HybridEncoder.js
Created January 24, 2023 17:48
Hybrid JSON / UINT8ARRAY... BINARY SERIALIZER (with json string yet parsed with utf-zap and concatenated at the end of the uint8array)
/*
The MIT License (MIT)
Copyright (c) 2023 Matias Affolter
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@vipertechofficial
vipertechofficial / Nuclei.js
Last active January 10, 2023 13:25
Working on a FASTER BYTE array from/to OBJECT SERIALIZER with Head (three), Neck (properties heap) and Body (values heap)
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 Affolter Matias
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@vipertechofficial
vipertechofficial / Elemental92.js
Last active January 3, 2023 22:30
AWESOME - Get your base64 a bit of futurism --> BASE 92 !!!
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 Affolter Matias
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@vipertechofficial
vipertechofficial / cloudflare-deepai-web-worker-api-javascript.js
Created May 4, 2022 15:57
Use cloudflare and base64 to work with deepAI image processing easily without having to use the API-KEY in client-side...
// CLIENT-SIDE
function postJSON(url, payload, callback_function, content_type = "application/x-www-form-urlencoded") {
// This function is required because JSON is weird with some char
function clean_json_text(json_text) {
json_text = json_text.replace(/\\n/g, "\\n")
.replace(/\\'/g, "\\'")
.replace(/\\"/g, '\\"')
@vipertechofficial
vipertechofficial / resize-image-javascript.js
Created May 4, 2022 12:43
Resize Images in JavaScript in Web Worker with fallback using try catch to make it work on the main thread in old browser too
// CONST:
// imgd_data (you get img_data using a canvas, please get familiar with canvas)
// no_transparent (Boolean to know which file format to use)
// pxl_width (Simply width of the image)
// pxl_height (Simply height of the image)
// resize_width (Which size of width will it get at the end?)
try { // Can work in Web Worker so you can run it on a CPU thread different from the main one which doesn't freeze the UI
var imgd = null;
@vipertechofficial
vipertechofficial / get-a-map-of-colors-in-javscript.js
Created April 30, 2022 19:53
Get a map of pixel and their corresponding colors in Javascript so in other words a palette and a list of the color index (to be used with my other gist and something like RGBQuant.js)
_get_pixels_palette_and_list_from_image_data = (image_data) => {
const image_data_data = image_data.data;
let new_pxl_colors = [];
let new_pxl_colors_set = new Set();
let new_pxls = new Array(image_data.width * image_data.height);
for (let i = 0; i < image_data_data.length; i += 4) {
const color_hex = this._get_hex_color_from_rgba_values(image_data_data[index], image_data_data[index+1], image_data_data[index+2], image_data_data[index+3]);
@vipertechofficial
vipertechofficial / some-similar-to-Instagram-filters-in-JavaScript.js
Created April 30, 2022 19:36
Some RGBA filters for color correction and manipulation in JavaScript which makes results similar to those observed in the Instagram application.
_get_filters = () => {
return {
".1997": {
"a": Uint8ClampedArray.of(0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34, 35, 37, 38, 39, 41, 42, 44, 45, 46, 48, 49, 50, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 146, 147, 148, 149, 150, 151, 152, 153, 153, 154, 155, 156, 157, 158, 159, 160, 160, 161, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 171, 172, 172, 173, 174, 175, 176, 177, 178, 178, 179, 180, 181, 182, 183, 183, 184, 185, 186, 187, 188, 188, 189, 190, 191, 192, 193, 193, 194, 195, 196, 197, 198, 199, 199, 200, 201, 202, 203, 204, 204, 205, 206, 207,
@vipertechofficial
vipertechofficial / fastest-rgba-hsla-hex-conversion.js
Created April 30, 2022 19:23
Fastest RGBA, HSLA, and HEX color conversion, formatting and blending (mix) in JavaScript developed for the pixa.pics project.
_format_color = (color) => { // Supports #fff (short rgb), #fff0 (short rgba), #e2e2e2 (full rgb) and #e2e2e2ff (full rgba)
const hex = color || "#00000000";
const hex_length = hex.length;
if(hex_length === 9) {
return hex;
} else if (hex_length === 7) {