Skip to content

Instantly share code, notes, and snippets.

View nestarz's full-sized avatar
🏠
Working from home

Elias Rhouzlane nestarz

🏠
Working from home
View GitHub Profile
export default () => ({
name: "deno_read",
setup(build) {
build.onLoad(
{ filter: /.*\.(t|j)s(x|)/, namespace: "file" },
async ({ path }) => ({
contents: await Deno.readTextFile(path),
loader: "tsx",
})
);
type EventTargetWithAddListener = EventTarget & {
listeners: Map<string, any>;
addEventListener(
type: string,
listeners: Map<string, (event: Event) => any>,
options?: boolean | AddEventListenerOptions
): void;
};
export const handleEventEmitter = (
@nestarz
nestarz / websocketstream-polyfill.js
Last active February 22, 2023 17:18
websocketstream-polyfill.js
export const ReadableStream = window.ReadableStream && window.ReadableStream.prototype[Symbol.asyncIterator] ?
window.ReadableStream : (() => {
function ReadableStream (...args) {
let readers = []
let obj = args[0]
let stream = new window.ReadableStream(...args)
// patch cancel to release lock
let _cancel = stream.cancel
import time
from typing import List
import numpy as np
import pysbd
import torch
from TTS.config import load_config
from TTS.tts.models import setup_model as setup_tts_model
import { h } from "preact";
import { createContext, ComponentChildren } from "preact";
import { useContext, useRef } from "preact/hooks";
import { Signal, signal, useSignalEffect } from "@preact/signals";
interface ComboboxProps {
children: ComponentChildren;
value: Signal<string>;
onChange: (value: string | null) => void;
nullable?: boolean;
import { runHttpQuery } from 'https://deno.land/x/gql@1.1.2/common.ts'
import type { GQLRequest, GQLOptions, GraphQLParams } from 'https://deno.land/x/gql@1.1.2/types.ts'
import { renderPlaygroundPage } from 'https://deno.land/x/gql@1.1.2/graphiql/render.ts';
/**
* Create a new GraphQL HTTP middleware with schema, context etc
* @param {GQLOptions} options
*
* @example
* ```ts
@nestarz
nestarz / polling.ts
Last active December 23, 2022 02:57
polling.ts
export default (fn, ms = 1000) => {
const connections = new Map();
let id: number | undefined;
const poll = async () => {
if (connections.size > 0)
await fn().then((results) =>
connections.forEach((conn) => conn(results))
);
if (connections.size > 0) id = setTimeout(poll, ms);
};
import { runHttpQuery } from 'https://deno.land/x/gql@1.1.2/common.ts'
import type { GQLRequest, GQLOptions, GraphQLParams } from 'https://deno.land/x/gql@1.1.2/types.ts'
import { renderPlaygroundPage } from 'https://deno.land/x/gql@1.1.2/graphiql/render.ts';
/**
* Create a new GraphQL HTTP middleware with schema, context etc
* @param {GQLOptions} options
*
* @example
* ```ts
@nestarz
nestarz / ffmpeg-xstack.js
Last active May 12, 2022 19:10
ffmpeg xstack javascript layout tool
const range = (N) => [...Array(N).keys()];
const outer = ([v1, v2]) => v1.map((x) => v2.map((y) => `${x}_${y}`));
const tile = (N, fn) =>
range(N).map((i, _, arr) => arr.slice(0, i).map(fn).join("+") || 0);
const layout = (N) =>
outer([tile(N, (k) => `w${k * N}`), tile(N, (k) => `h${k}`)])
.flat()
.join("|");
@nestarz
nestarz / globalQueue.js
Last active December 20, 2021 12:59
Promise queue with concurrency control
const queue = (id, concurrency = 1) => {
const d = { running: 0, queue: [] };
const c = (globalThis._RQ ?? {})[id] ?? d;
globalThis._RQ = { ...(globalThis._RQ ?? {}), [id]: c };
const inc = (fn) => (c.running++, fn());
return (task) =>
(c.running < concurrency
? Promise.resolve(inc(task))
: new Promise((res) => c.queue.push(() => res(inc(task))))
).finally(