Skip to content

Instantly share code, notes, and snippets.

View asvny's full-sized avatar
🎯
Focusing

Annamalai Saravanan asvny

🎯
Focusing
View GitHub Profile
@asvny
asvny / eval.js
Created November 4, 2020 10:22 — forked from natemoo-re/eval.js
Safe(ish) Eval
// Adopted from Alpine.js
// https://github.com/alpinejs/alpine/blob/b6e07b2775de444c5f9bdc4d94accb7b720fd6a7/src/utils.js#L59
function saferEval(expression, context, additionalHelperVariables = {}) {
return (new Function(['$data', ...Object.keys(additionalHelperVariables)], `var result; with($data) { result = ${expression} }; return result`))(
context, ...Object.values(additionalHelperVariables)
)
}
export default function sandboxedEval(expression, context = {}) {
@asvny
asvny / RouteParams.ts
Created November 4, 2020 19:30 — forked from natemoo-re/RouteParams.ts
Typed parameter object from path
type RestParam<S extends string> = S extends `...${infer A}` ? A : never;
type StandardParam<S extends string> = S extends `...${infer A}` ? never : S;
type ExtractParams<S extends string> = S extends `[${infer A}]` ? A : never;
type TupleToUnion<T extends any[]> = T[number];
type Split<S extends string> =
string extends S ? string[] :
S extends '' ? [] :
S extends `${infer T}/${infer U}` ? [T, ...Split<U>] :
[S];
@asvny
asvny / esbuild-relay.js
Created February 25, 2021 01:31 — forked from sciyoshi/esbuild-relay.js
Esbuild plugin for compiling relay queries
import { promises } from "fs";
import crypto from "crypto";
import path from "path";
import { print, parse } from "graphql";
const plugin = {
name: "relay",
setup: build => {
build.onLoad({ filter: /\.tsx$/, namespace: "" }, async args => {
let contents = await promises.readFile(args.path, "utf8");
@asvny
asvny / hls.sh
Created November 16, 2024 09:14 — forked from stenuto/hls.sh
HLS ffmpeg script
#!/bin/bash
# Function to display usage information
usage() {
echo "Usage: $0 /path/to/input.mp4 [ /path/to/output_directory ]"
exit 1
}
# Check if at least one argument (input file) is provided
if [ $# -lt 1 ]; then