Skip to content

Instantly share code, notes, and snippets.

View Mhmdrza's full-sized avatar
👽
Mostly in the zone

Mhmdrz_a Mhmdrza

👽
Mostly in the zone
View GitHub Profile
@bmaupin
bmaupin / free-backend-hosting.md
Last active July 23, 2024 01:45
Free backend hosting
@Klerith
Klerith / urlBase64ToUint8array.js
Last active April 7, 2024 14:16
web-push: urlBase64ToUint8array
// Web-Push
// Public base64 to Uint
function urlBase64ToUint8Array(base64String) {
var padding = '='.repeat((4 - base64String.length % 4) % 4);
var base64 = (base64String + padding)
.replace(/\-/g, '+')
.replace(/_/g, '/');
var rawData = window.atob(base64);
var outputArray = new Uint8Array(rawData.length);
@kedevked
kedevked / tfjs-webworker.html
Created March 14, 2019 02:32
use tensorflow.js in a web worker
<head>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.14.2/dist/tf.min.js"></script>
<script>
const worker_function = () => {
onmessage = () => {
console.log('from web worker')
this.window = this
importScripts('https://cdn.jsdelivr.net/npm/setimmediate@1.0.5/setImmediate.min.js')
importScripts('https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.10.3')
async function compressAndBase64(file, {
quality = 91,
scaleFactor = Math.log(file.size) / 13, // scale down images over 1MB
} = {}) {
return new Promise((res, rej)=>{
const img = new Image();
img.src = URL.createObjectURL(file);
img.onload = function() {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');