Skip to content

Instantly share code, notes, and snippets.

View eser's full-sized avatar
🎙️
Streaming on YouTube - https://eser.live

Eser Ozvataf eser

🎙️
Streaming on YouTube - https://eser.live
View GitHub Profile
import { useEffect, useRef, useState } from "preact/hooks";
const ENDPOINT = "https://whole-cat-70.deno.dev/";
const COLLECTION = "dil";
function getEndpoint() {
return `${ENDPOINT}${COLLECTION}`;
}
async function getFromServer(setItems: (items: string[]) => void) {
function getFunctionParametersFromString(funcStr) {
const match = funcStr.match(/(?:function.*?\(|\()(.*?)(?:\)|=>)/);
if (match && match[1]) {
return match[1].split(',').map(p => p.trim());
}
return [];
}
function getFunctionParameters(func) {
@eser
eser / universal-wasm-loader.js
Last active September 13, 2023 16:49
Universal WASM Loader
export const getWasmCode = async (url) => {
switch (url.protocol) {
case "file:":
const assemblyUrl = url.pathname.substr(0, 1) === "/"
? url.pathname.substr(1)
: url.pathname;
if (globalThis.Deno !== undefined) {
return Deno.readFile(assemblyUrl);
}
@eser
eser / basic_di.ts
Created August 28, 2023 22:11
Basic DI with typescript
Symbol.metadata ??= Symbol("metadata");
// base
type ContainerItemKinds = "class" | "value";
type ContainerKey = symbol | string | number;
type ContainerItem = { obj: unknown, kind: ContainerItemKinds };
const container = new Map<ContainerKey, ContainerItem>();
const inject = (key: ContainerKey, value: unknown, kind: ContainerItemKinds = "value") => {
container.set(key, { obj: value, kind: kind });
@eser
eser / link-effect.css
Created August 22, 2023 21:54
background <a> effect
validateModel(): void {
this.logger.debug(`validating model for ${this.name}`);
asserts.assertExists(this.name, "name is required");
asserts.assert(this.name.length > 0, "name is required");
asserts.assertExists(this.version, "version is required");
asserts.assert(this.version.length > 0, "version is required");
const integrationFeatures = [
// taken from https://deno.land/[email protected]/node/internal/crypto/_randomBytes.ts?source
// licensed under MIT License
const MAX_RANDOM_VALUES = 65536;
const MAX_SIZE = 4294967295;
function generateRandomBytes(size: number) {
if (size > MAX_SIZE) {
throw new RangeError(
`The value of "size" is out of range. It must be >= 0 && <= ${MAX_SIZE}. Received ${size}`,
);
@eser
eser / camel-caps.js
Last active November 14, 2022 18:46
const camelCaps = (str) => {
let nextShouldBeUpper = true;
let result = "";
for (let i = 0; i < str.length; i++) {
result += nextShouldBeUpper ? str[i].toLocaleUpperCase() : str[i].toLocaleLowerCase();
nextShouldBeUpper = (str[i] === " ") || !nextShouldBeUpper;
}
return result;
const publicJwk = {
"kty": "RSA",
"kid": "",
"n": "",
"e": "AQAB"
};
const privateJwk = {
"kty": "RSA",
"kid": "",
@eser
eser / wordlist.txt
Last active January 20, 2022 17:33
AGENT
AGILE
ALGOL
ALLOC
AMIGA
ARRAY
ASCII
ASIDE
ASSET
ASSOC