Skip to content

Instantly share code, notes, and snippets.

View rachidelaid's full-sized avatar

rachid el aid rachidelaid

View GitHub Profile
function catAndMouse(x, y, z) {
const diffA = Math.abs(z-x);
const diffB = Math.abs(z-y);
if(diffA === diffB) return "Mouse C";
return diffA < diffB ? "Cat A" : "Cat B";
}
function saveThePrisoner(n, m, s) {
return (m%n+s-1)%n ? (m%n+s-1)%n : n
}
function angryProfessor(k, a) {
const onTimeStudents = a.filter(s => s <= 0).length
return onTimeStudents >= k ? "NO" : "YES"
}
@rachidelaid
rachidelaid / hike.js
Created May 10, 2022 07:24
this is an algo peoblem from hacker rank
/*
this is an algo peoblem from hacker rank https://www.hackerrank.com/challenges/counting-valleys/problem?isFullScreen=true
*/
function countingValleys(steps, path) {
let count = 0;
let level = 0;
path.split("").forEach(unit => {
if(unit === "D") {
@rachidelaid
rachidelaid / drawing_book.js
Created May 3, 2022 07:37
drawing book hackerrank
/*
https://www.hackerrank.com/challenges/drawing-book/problem?isFullScreen=true
Given and , find and print the minimum number of pages that must be turned in order to arrive at page .
*/
function pageCount(n, p) {
let index = 0;
const chunks = [];
const arr = [...Array(n + 1).keys()];
for (let i = 0; i < arr.length; i += 2) {
function jumpingOnClouds(c, k) {
let index = 0;
let energy = 100;
let stop = false;
while (!stop) {
if (c[index] === 1) {
energy -= 2;
}
@rachidelaid
rachidelaid / jest.config.js
Created January 19, 2022 13:06 — forked from johno/jest.config.js
Mock localStorage with Jest for React testing
module.exports = {
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
setupFiles: ['./test-setup.js']
}
@rachidelaid
rachidelaid / exemple-1.md
Created January 17, 2022 13:08
Is it DRY? Exercise
const pets = ['Cat', 'Dog', 'Bird', 'Fish', 'Frog', 'Hamster', 'Pig', 'Horse' 'Lion', 'Dragon'];
// Print all pets
console.log(pets[0]);
console.log(pets[1]);
console.log(pets[2]);
console.log(pets[3]);
...

This block of code is not DRY.

@rachidelaid
rachidelaid / gist:17b4f8da5bf366edbd6debdd383c0481
Created June 20, 2021 12:52 — forked from su-v/gist:9965739
Inkscape / SVG on GitHub
@rachidelaid
rachidelaid / node_nginx_ssl.md
Created February 26, 2020 20:04 — forked from bradtraversy/node_nginx_ssl.md
Node app deploy with nginx & SSL

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for Digital Ocean

If you use the referal link below, you get $10 free (1 or 2 months) https://m.do.co/c/5424d440c63a

2. Create a droplet and log in via ssh

I will be using the root user, but would suggest creating a new user