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
@ali-master
ali-master / redux-from-scratch.ts
Created July 9, 2021 19:12
A simple redux from scratch
/**
* Redux
* - getState()
* - subscribe()
* - dispatch() -> ui -> state
* - combineReducer
*
*
* - replaceReducer
* - injectReducer
@ali-master
ali-master / time-overlap.js
Created May 21, 2021 14:31
Check if two time strings have overlap in Javascript.
function parseTimeString(str) {
return parseFloat(str.replace(":", "."))
}
function hasConflict(firstTime, secondTime) {
const firstTimeStart = parseTimeString(firstTime.start)
const firstTimeEnd = parseTimeString(firstTime.end)
const secondTimeStart = parseTimeString(secondTime.start)
const secondTimeEnd = parseTimeString(secondTime.end)
if((firstTimeStart <= secondTimeEnd) && (secondTimeStart <= firstTimeEnd)) {
@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 / scratch_16.js
Created December 8, 2020 13:57
Find missing number in an array of numbers
// Find theoretical sum of the consecutive numbers using a variation of Gauss Sum.
// Formula: [(N * (N + 1)) / 2] - [(M * (M - 1)) / 2];
// N is the upper bound and M is the lower bound
function missingNumber(n) {
let upperBound = 0;
let lowerBound = 99999999;
let sum = 0;
for (let i = 0; i < n.length; i++) {
@ali-master
ali-master / Operator-mono-ssm.css
Created August 9, 2020 13:25
Operator mono ssm css font
@font-face {
font-family: 'Operator Mono SSm';
src: url(data:application/x-font-woff;base64,d09GRgABAAAAAGpyABIAAAAAytgAAQAAAABoTAAAAiYAAAaTAAAAAAAAAABHREVGAABnkAAAAB0AAAAeACgA5UdQT1MAAGewAAAAQAAAAFgsnhyBR1NVQgAAZ/AAAABbAAAAhOs/LbZPUy8yAAACCAAAAFcAAABgWBrmPWNtYXAAAAO8AAACcQAAA2iGH4kRY3Z0IAAACIAAAABkAAAAZBmhB5pmcGdtAAAGMAAAAQIAAAFzBlmcN2dhc3AAAGeEAAAADAAAAAwADwAaZ2x5ZgAACqQAAFZbAACtACBUat1oZG14AAADtAAAAAgAAAAIAAAA5GhlYWQAAAGUAAAAMwAAADYHchYnaGhlYQAAAcgAAAAeAAAAJAZuAsFobXR4AAACYAAAAVEAAANiAJlRdmxvY2EAAAjkAAABwAAAAcAXX0J0bWF4cAAAAegAAAAgAAAAIAMPBGtuYW1lAABhAAAABIkAAAvHAxl5pXBvc3QAAGWMAAAB9wAAApzNbPx+cHJlcAAABzQAAAFKAAAB98jebkJ42mNgZGBgYPQ5c3mdAkc8v81XBnnmF0ARhku3Dt2B06z/zjK1MH8EcjkYmECiALPzD1UAeNpjYGRgYD7w34JBg2kbAxAwtTAwMqCCSwBdKgQ1AAAAAQAAAN8CEAAfAEcABAABAAAAAAAKAAACAAISAAIAAXjaY2BmKmR0ZWBlYGFqZmr+f5dhE4hmcGGMY/BhzGVgYGJg4GQAgwUMDPYCDAxRDFDgoeacD6R4H3IzK/y3YDjBfIDhA5DfDZJjUmDaAKQUGJgAC0sPiAB42m3SvUtCYRTH8XMvhIND1NTS2pBFVmREUEFJg4tKSRkhFmYUQdrLkIQQNDUEZrNrm1tLq/9EU1uLQQm193vqG8TlKh/OfXleznPO9Uesz/j5lR9f
@ali-master
ali-master / sugarCube.js
Last active May 19, 2020 07:35
Find the the sugar cube box which it's cubes weight is different with other boxes.
function findDifferentSugarCube(boxes) {
const selectBoxesOfCubes = boxes.reduce((acc, current, index) => {
acc.push(current.slice(0, index + 1));
return acc;
}, []);
let weight = 0;
let no = 0;
for (let i = 0; i < selectBoxesOfCubes.length; i++) {
function redGreenBlue(r, g, b) {
const leftArray = []
const createdGroupsNo = [];
function createGroup (column, type){
if (column % 3 <= 2) {
if (column >= 3) {
column -= 3;
type && createdGroupsNo.push(Array(3).fill(type));
@ali-master
ali-master / docker-compose.yml
Last active March 27, 2020 18:36
Sample docker-compose
version: "3.7"
services:
# Zookeeper configuration
zookeeper-server:
image: "bitnami/zookeeper:latest"
networks:
- kafka
- internal
ports:
@ali-master
ali-master / flatten.ts
Created March 9, 2020 18:01
Flatten an array of everything in deep with JavaScript
function flatten(arr: any[]): any[] {
return arr.reduce((acc, curr) =>{
if(Array.isArray(curr)) {
acc = acc.concat(flatten(curr));
}else{
acc = acc.concat(curr);
}
return acc;
}, [])
@ali-master
ali-master / treeMenu.ts
Created March 9, 2020 18:01
Implementation of tree menu with JavaScript in deep
interface Level {
id: string;
text: string;
children?: Level[];
}
const levels: Level[] = [
{
id: "1",
text: "Category 1",