Skip to content

Instantly share code, notes, and snippets.

View ali-master's full-sized avatar
Working hard on a new Crypto exchange engine...

Ali Torki ali-master

Working hard on a new Crypto exchange engine...
View GitHub Profile
@ali-master
ali-master / README.md
Created October 21, 2024 21:00
Macos Operation not permitted issue solution

I find a solution for this, in finder, if the hosts file has a lock on it, use this command to unlock it:

sudo chflags nouchg,noschg /etc/hosts

then it will be editable by root, so you can use sudo nano /etc/hosts.

BTY, you can find hosts file in finder by this command: open /etc.

@ali-master
ali-master / date-timezone-converter.ts
Created October 19, 2024 08:40
Javascript Date Timezone awareness utility
export const convertDate = (date: Date | string) => {
if (typeof date === "string") {
const d = new Date(date);
return d.toISOString().slice(0, 19).replace("T", " ");
}
return date.toISOString().slice(0, 19).replace("T", " ");
};
export const getNow = () => {
return new Date(convertDate(new Date()));
@ali-master
ali-master / retryDynamicImport.ts
Created October 13, 2024 20:29 — forked from mberneti/retryDynamicImport.ts
This utility function retryDynamicImport enhances React’s lazy loading mechanism by adding retry logic with a versioned query parameter. It retries importing a component multiple times in case of failure, which can be useful for bypassing browser cache or dealing with intermittent network issues. It can be used as a drop-in replacement for React…
// Usage:
// Replace React.lazy(() => import('x'));
// with retryDynamicImport(() => import('x'));
import { ComponentType, lazy } from 'react';
const MAX_RETRY_COUNT = 15;
const RETRY_DELAY_MS = 500;
// Regex to extract the module URL from the import statement
@ali-master
ali-master / index.ts
Created September 29, 2024 16:16
NodeJS Hook0
import axios from "axios";
import { randomUUID } from 'crypto';
const checkProcessEnv = () => {
if (
!process.env.HOOK0_APPLICATION_ID ||
!process.env.HOOK0_APPLICATION_SECRET
) {
throw new Error('Cannot subscribe to webhooks without Hook0 settings');
}
@ali-master
ali-master / timespan.ts
Created September 19, 2024 14:30
Javascript human time converter
export type TimeSpanUnit = "ms" | "s" | "m" | "h" | "d" | "w";
export class TimeSpan {
constructor(value: number, unit: TimeSpanUnit) {
this.value = value;
this.unit = unit;
}
public value: number;
public unit: TimeSpanUnit;
@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.