Skip to content

Instantly share code, notes, and snippets.

View brunoh3art's full-sized avatar
🟢
if you can dream it. you can do it

Bruno Martins brunoh3art

🟢
if you can dream it. you can do it
View GitHub Profile
class ResourceLoader {
static jsZipLoaded = false;
static async loadJSZip() {
if (this.jsZipLoaded) return Promise.resolve();
return new Promise((resolve, reject) => {
if (typeof JSZip !== 'undefined') {
this.jsZipLoaded = true;
resolve();

running:

bash create-vod-hls.sh beach.mkv

will produce:

    beach/
      |- playlist.m3u8
 |- 360p.m3u8
export type Replace<T, R> = Omit<T, keyof R> & R;
import { TRPCError } from '@trpc/server';
import { TRPC_ERROR_CODE_KEY } from '@trpc/server/dist/rpc';
function trpcAssert(
condition: unknown,
msg: string,
code: TRPC_ERROR_CODE_KEY = 'INTERNAL_SERVER_ERROR'
): asserts condition {
if (!condition) {
throw new TRPCError({
// trpc.ts
import { trpcTracingMiddleware } from "@baselime/node-opentelemetry";
const t = initTRPC.context<typeof createTRPCContext>().create({
...
});
// add the middleware to all the procedures you want to trace
export const publicProcedure = t.procedure.use(trpcTracingMiddleware({ collectInput: true }))
// SERVER
export const storageRouter = createTRPCRouter({
requestVideoUploadUrl: protectedProcedure
.input(z.object({ videoId: z.string().uuid() }))
.query(async ({ input }) => {
const { videoId } = input
const signedUrl = await getSignedUrl(
r2,
@brunoh3art
brunoh3art / createSafeContext.tsx
Created February 27, 2024 15:29
create Safe Context
import React, { createContext, useContext } from "react";
export function createSafeContext<ContextValue>(errorMessage: string) {
const Context = createContext<ContextValue | null>(null);
const useSafeContext = () => {
const ctx = useContext(Context);
if (ctx === null) {
throw new Error(errorMessage);
@brunoh3art
brunoh3art / useConfirmation.ts
Created January 26, 2024 06:52 — forked from KristofferEriksson/useConfirmation.ts
Custom React hook for double-click confirmation for critical actions
import { useCallback, useEffect, useRef, useState } from "react";
/**
* Custom React hook for double-click confirmation for critical actions.
*
* @param action - The action to be executed on the second click.
* @param timeout - Time in milliseconds to reset the unlocked state.
* @returns The current unlocked state and the trigger function.
*/
const useConfirmation = (action: () => void, timeout: number = 5000) => {