Skip to content

Instantly share code, notes, and snippets.

View ali-master's full-sized avatar
working on multiple AI Native Products

Ali Torki ali-master

working on multiple AI Native Products
View GitHub Profile
@ali-master
ali-master / sound-fx.js
Created August 29, 2024 17:24
Javascript Sound FX
class SoundFX {
#isSoundEnabled;
#COIN_FX = 'https://themushroomkingdom.net/sounds/wav/smw/smw_coin.wav';
#ERROR_FX = 'https://themushroomkingdom.net/sounds/wav/smw/smw_lemmy_wendy_incorrect.wav';
#DECREASE_FX = 'https://themushroomkingdom.net/sounds/wav/smw/smw_stomp_bones.wav';
#INCREASE_FX = 'https://themushroomkingdom.net/sounds/wav/smw/smw_stomp.wav';
@ali-master
ali-master / totp.ts
Created August 29, 2024 11:21
NodeJS Generate TOTP
import { createHmac } from "crypto";
import { decode } from "hi-base32";
interface Options {
period: number;
digits: number;
timestamp?: number;
}
export function generateTOTP(key: string, options: Options): string {
@ali-master
ali-master / publish_to_npm.yml
Created August 10, 2024 19:18
Publish to NPM github action
name: Publish To NPM
on:
push:
branches: [master, beta]
jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
@ali-master
ali-master / README.md
Created August 9, 2024 20:14
NextJS Server Only Context API

NextJS Server Only Context API

Tiny wrapper around cache to have request-scoped context for server components. No more prop drilling!

Note: when navigating on the client side the layout is not re-rendered, so you need to set the context both in the page and in the layout.

export const [getLocale, setLocale] = ServerContext("en");
@ali-master
ali-master / README.md
Created August 4, 2024 18:20
React Draggable Curved Menu

A curved menu component that rotates while being dragged. It features famous furniture designs, with the middle item highlighted. The component is built using Framer Motion. A similar effect could be achieved with CSS's scroll() and animation-timeline, but this would not (yet) be fully functional on mobile devices.

@ali-master
ali-master / README.md
Created August 4, 2024 18:19
React Popover Slide Selector

A popover slide selector component that reveals a list of items on click. The list items are avatars from my last 10 GitHub followers. The component is inspired by the Telegram iOS app.

@ali-master
ali-master / stack.tsx
Created August 4, 2024 14:06
React Stats Stack component
import { motion } from "framer-motion";
import { useState } from "react";
const runs = [
{
distance: 10.29,
pace: "5:14 /km",
time: "53m 49s",
},
{
@ali-master
ali-master / timeline.tsx
Created August 4, 2024 14:05
React Timeline component
import React, { useRef, useState } from "react";
import { motion } from "framer-motion";
const years = Array.from({ length: 2024 - 1993 + 1 }, (_, i) => 2024 - i);
export default function Timeline() {
const [hoveredIndex, setHoveredIndex] = useState<number | null>(null);
const [selected, setSelected] = useState<number | null>(null);
const handleMouseEnter = (index: number) => {
@ali-master
ali-master / README.md
Created July 15, 2024 19:49
UUIDv7 in typescript

UUIDv7 is a 128-bit unique identifier like it's older siblings, such as the widely used UUIDv4. But unlike v4, UUIDv7 is time-sortable with 1 ms precision. By combining the timestamp and the random parts, UUIDv7 becomes an excellent choice for record identifiers in databases, including distributed ones.

Let's briefly explore the UUIDv7 structure and move on to the zero-dependency implementations in 33 languages (as ranked by the Stack Overflow survey).

These implementations may not be the fastest or most idiomatic, but they are concise and easy to understand. Many of the code examples are interactive (but the results are cached, so you won't see different UUIDs very often).

@ali-master
ali-master / hot-keys.hook.ts
Created July 11, 2024 13:26
React Keyboard hot keys Hooks
import { useEffect } from "react";
import hotkeys from "hotkeys-js";
// Types
import type { KeyHandler } from "hotkeys-js";
/**
* Filter function to ignore hotkeys when typing in an input, textarea or select
* @param {KeyboardEvent} event
* @returns {boolean}
*/