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 / 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 / ubuntu-docker-install.sh
Created April 28, 2024 08:15 — forked from kolosek/ubuntu-docker-install.sh
Ubuntu 22.04 docker and docker-compose install
sudo sysctl -w vm.max_map_count=262144
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu `lsb_release -cs` stable"
sudo apt update -y
sudo apt install docker-ce -y
# Docker-compose
mkdir -p ~/.docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
@ali-master
ali-master / docker-compose
Created April 5, 2024 20:44 — forked from hexfusion/docker-compose
etcd cluster v3 docker-compose example
version: '2'
services:
etcd-1:
image: gcr.io/etcd-development/etcd:v3.3.9
restart: always
ports:
- 2379
- 2380
volumes:
@ali-master
ali-master / useBroadcastLeader.ts
Created April 4, 2024 04:05 — forked from tannerlinsley/useBroadcastLeader.ts
A React Hook to determine if a tab of your application is the "leader" using BroadcastChannel and leader election
import { BroadcastChannel, createLeaderElection } from 'broadcast-channel'
import React from 'react'
const channels = {}
export function useBroadcastLeader(id = 'default') {
const [isBroadcastLeader, setIsBroadcastLeader] = React.useState(false)
React.useEffect(() => {
if (!channels[id]) {
@ali-master
ali-master / parseq.js
Created December 3, 2022 13:05 — forked from aSapien/parseq.js
Parallel / Sequential execution control flow with Promises in JS #javascript
export const parallel = (...fs) => sequential(
() => fs.map(f => f()),
Promise.all.bind(Promise));
export const sequential = (f, ...fs) => val => Promise.resolve()
.then(() => f(val))
.then(fs.length ? sequential(...fs) : id => id);
--log_gc (Log heap samples on garbage collection for the hp2ps tool.)
type: bool default: false
--expose_gc (expose gc extension)
type: bool default: false
--max_new_space_size (max size of the new generation (in kBytes))
type: int default: 0
--max_old_space_size (max size of the old generation (in Mbytes))
type: int default: 0
--max_executable_size (max size of executable memory (in Mbytes))
type: int default: 0
@ali-master
ali-master / maybe.ts
Created April 23, 2021 22:20 — forked from vagarenko/maybe.ts
Maybe type in Typescript.
/**
* The Maybe type encapsulates an optional value.
*/
export class Maybe<T> {
/** Create an empty value. */
static nothing<T>(): Maybe<T> {
return new Maybe<T>(undefined);
}
/** Create a non-empty value. */
@ali-master
ali-master / pm2.json
Created October 3, 2018 22:44 — forked from MikeNats/pm2.json
using PM2 for run ES6 (babel) application
{
"apps": [{
"name": "Application",
"exec_interpreter": "./node_modules/babel-cli/bin/babel-node.js",
"script": "./bin/www",
"args": [],
"watch": ["public", "package.json", "pm2.development.json"],
"ignore_watch": ["public"],
"watch_options": {
"persistent": true,
@ali-master
ali-master / destructuring.js
Created December 3, 2017 07:42 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring. Runnable demos and slides about the same topic: http://git.mikaelb.net/presentations/bartjs/destructuring
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => [1, 2, 3];
@ali-master
ali-master / unistore.js
Created October 22, 2017 07:19 — forked from developit/unistore.js
dead simple centralized state container ("store"), with preact bindings.
import { h, Component } from 'preact';
/** Creates a new store, which is a tiny evented state container.
* @example
* let store = createStore();
* store.subscribe( state => console.log(state) );
* store.setState({ a: 'b' }); // logs { a: 'b' }
* store.setState({ c: 'd' }); // logs { c: 'd' }
*/