Skip to content

Instantly share code, notes, and snippets.

View exhesham's full-sized avatar
💭
the grass is greener over here, you're the fog that makes it so clear

Hesham Yassin exhesham

💭
the grass is greener over here, you're the fog that makes it so clear
View GitHub Profile
@exhesham
exhesham / Network Kit (Ping & Scan)
Last active November 16, 2023 02:56
This is the code for the android app named Network Kit (Ping & Scan)You can find the app in this link:https://play.google.com/apps/publish/?dev_acc=00133172886064494147#AppDashboardPlace:p=network.hesham.pinger
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
@exhesham
exhesham / AndroidManifest.xml
Last active March 16, 2022 19:22
Google sign in process
<application>
....
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
@exhesham
exhesham / sol2.log
Created December 12, 2021 08:24
sol2.log
[LOG]: "Total tasks: 10"
[LOG]: "worker 1 is started"
[LOG]: "worker 1 handles task"
[LOG]: " --> Task 1 started"
[LOG]: "worker 2 is started"
[LOG]: "worker 2 handles task"
[LOG]: " --> Task 2 started"
[LOG]: "worker 3 is started"
[LOG]: "worker 3 handles task"
[LOG]: " --> Task 3 started"
@exhesham
exhesham / sol2-run.ts
Created December 12, 2021 08:24
sol2-run.ts
await Promise.all([worker(1), worker(2), worker(3), worker(4)]);
@exhesham
exhesham / sol2-worker.ts
Created December 12, 2021 08:23
sol2-worker.ts
let worker = async (index: number) => {
console.log(`worker ${index} is started`);
while(tasksQueue.length > 0) {
console.log(`worker ${index} handles task`);
let task = tasksQueue[0]; // should be atomic
tasksQueue = tasksQueue.slice(1);
await task();
console.log(`worker ${index} finished handling task`);
}
console.log(`worker ${index} is retired`);
@exhesham
exhesham / sol2-configtasks.ts
Created December 12, 2021 08:22
sol2-configtasks.ts
let idx =1, tasksQueue = Array(numberOfTasks).fill(1)
.map(v => Math.round(Math.random() * 30) + v)
.map(v => (() => taskExecutor({delay: v, index: `${idx++}` })));
@exhesham
exhesham / sol1-output.log
Created December 12, 2021 08:21
sol1-output.log
[LOG]: "* start running batch 0"
[LOG]: " --> Task 0 started"
[LOG]: " --> Task 1 started"
[LOG]: " --> Task 2 started"
[LOG]: " <-- Task 0 finished"
[LOG]: " <-- Task 1 finished"
[LOG]: " <-- Task 2 finished"
[LOG]: "* finished running batch 0"
[LOG]: "* start running batch 3"
[LOG]: " --> Task 3 started"
@exhesham
exhesham / task-executor.ts
Created December 12, 2021 08:20
task-executor.ts
let taskExecutor = async (task: {delay: number, index: string}) => {
console.log(` --> Task ${task.index} started`);
await sleep(task.delay);
console.log(` <-- Task ${task.index} finished`);
};
@exhesham
exhesham / sol1.ts
Created December 12, 2021 08:19
sol1.ts
async function solution1() {
for(let i = 0; i < tasksSleepInput.length; i+= chunkSize) {
let batch = tasksSleepInput.slice(i, i + chunkSize);
console.log(`* start running batch ${i}`);
await Promise.all(batch.map(taskExecutor));
console.log(`* finished running batch ${i}`);
}
}
@exhesham
exhesham / sol1-configtasks.ts
Created December 12, 2021 08:18
batch run 1
const chunkSize = 3;
const numberOfTasks = 10;
let tasksSleepInput = Array(numberOfTasks).fill(30).map(v => ({delay: v, index: '' }));
// add indices
Object.keys(tasksSleepInput).forEach(k => tasksSleepInput[Number.parseInt(k)].index = k);