Skip to content

Instantly share code, notes, and snippets.

View ali-master's full-sized avatar
🎯
Focusing on Something new!

Ali Torki ali-master

🎯
Focusing on Something new!
View GitHub Profile
--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 / typescript-session1.ts
Created December 10, 2021 19:13
Typescript Workshop(First session)
////////////////////
// Exclude
////////////////////
type MyExclude<T, L> = T extends L ? never : T;
type TestExclude = MyExclude<"a" | "b" | "c" | "d", "a" | "b">
////////////////////
// Extract
////////////////////
type MyExtract<T, L> = T extends L ? T : never;
@ali-master
ali-master / react-pwa-install-button.js
Created December 5, 2021 13:01
Install a PWA application manually in React.js
import React, { useEffect, useRef } from 'react'
export const PWAInstallButton = () => {
const deferredPrompt = useRef(null)
useEffect(() => {
const handlePrompt = (e) => {
// Prevent the mini-infobar from appearing on mobile
e.preventDefault()
// Stash the event so it can be triggered later.
@ali-master
ali-master / docker-compose.yml
Created December 2, 2021 20:51
Unleash self-hosted docker-compose version
version: "3.7"
services:
unleashDB:
expose:
- "5432"
image: postgres:13
container_name: unleashDB
networks:
- internal
@ali-master
ali-master / partial-require-only-one.ts
Created November 6, 2021 07:44
RequireOnlyOne & PartialOnlyOne in typescript
type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
[K in Keys]-?: Required<Pick<T, K>>;
}[Keys];
type PartialOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
[K in Keys]?: Partial<Pick<T, K>>;
}[Keys];
@ali-master
ali-master / converter.js
Created September 11, 2021 00:39
Two functions to convert from Celsius to Fahrenheit and back in Javascript
function toCelsius(fahrenheit) {
return (fahrenheit - 32) * 5 / 9;
}
function toFahrenheit(celsius) {
return (celsius * 9 / 5) + 32;
}
@ali-master
ali-master / redux-from-scratch.js
Created July 15, 2021 18:46
Redux from scratch without typescript
function createStore(reducer, preloadedState) {
if(typeof reducer !== "function") {
throw new Error("Reducer should be a function.");
}
if(typeof preloadedState === "function") {
throw new Error("PreloadedState can't be a function.");
}
let currentState = preloadedState;
@ali-master
ali-master / findAnagramGroups.ts
Created July 14, 2021 10:09
Given an array of strings, group anagrams together in Javascript
/**
* This problem was asked by Robinhood.
Given an array of strings, group anagrams together.
For example, given the following array:
['eat', 'ate', 'apt', 'pat', 'tea', 'now']
Return:
@ali-master
ali-master / maxIslandsCount.ts
Created July 13, 2021 23:03
Javascript Find max islands count in matrix
function dfs(graph: Grid) {
let max = 0;
let islandsCount = 0;
const visited: Grid<boolean> = [[], [], [], [], []];
for (let x = 0; x < graph.length; x++) {
for (let y = 0; y < graph[x].length; y++) {
if (!visited[x][y]) {
islandsCount = 1 + can(graph, x, y, visited);
@ali-master
ali-master / greedy.ts
Last active November 20, 2021 13:29
Check if we can go from top-left to the right-bottom in a Matrix which returns the path of way by javascript
const grid: Array<Array<number>> = [
[1, 0, 1, 1, 1],
[1, 1, 1, 0, 0],
[0, 1, 0, 1, 1],
[1, 0, 1, 1, 0],
[0, 0, 1, 1, 1]
];
console.log(solveGrid(grid));