Skip to content

Instantly share code, notes, and snippets.

View shayphs's full-sized avatar

Shay Pinhas shayphs

View GitHub Profile
@shayphs
shayphs / nvm-tutorial.md
Created March 11, 2023 12:29
nvm tutorial
@shayphs
shayphs / repeat-as-many.js
Created March 11, 2023 11:54
prototype - repeat as many
String.prototype.repeatAsMany = function(n){
console.log(this);
var str = '';
for (let index = 0; index < n; index++) {
str += this.toString();
}
return str;
}
@shayphs
shayphs / table-from-array.js
Created March 11, 2023 08:41
Create table and list from array with vanila js
function createTable(params) {
html = '';
list.forEach(element => {
html += '<tr>';
html += `<td>${element.firstName}</td>`;
html += `<td>${element.lastName}</td>`;
html += `<td>${element.age}</td>`;
html += '</tr>';
});
@shayphs
shayphs / ubuntu-swap.txt
Created March 11, 2023 08:33
how to add swap space on ubuntu
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04
free -h
sudo fallocate -l 3G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
free -h
@shayphs
shayphs / find-the-missing.js
Created March 11, 2023 08:20
In array from (0) to (n) we need to find the missing number with best of complicity O(n)
// array from 0 to n
// [0,1,3]
use strict
let myArr = [0,1,3];
function name(myArr) {
let myObj = {};
@shayphs
shayphs / reverse-int.js
Last active March 11, 2023 08:10
Simple trick to reverse int numbers
const reverseInt = (num) => {
return num.toString().split('').reverse().join('');
};
console.log(reverseInt(415)); // 514
console.log('be');
@shayphs
shayphs / my-promise-all.js
Last active March 11, 2023 08:11
Implemantation of promiseAll
function promiseAll(promises) {
const outputs = [];
let settledPromiseCounter = 0;
return new Promise((resolve, reject) => {
promises.forEach((promise, i) => {
promise.then((value)=> {
outputs[i] = value;
settledPromiseCounter++;
if (settledPromiseCounter === promises.length) {
resolve(outputs);
@shayphs
shayphs / simple-fibonacci.js
Last active March 11, 2023 08:12
A simple Fibonacci function
function fibo(num) {
let one = 1;
let two = 1;
let temp = 0;
let fiboo = [];
for (let index = 0; index < num; index++) {
temp = one + two;
fiboo.push(temp);
@shayphs
shayphs / deep-equal.js
Last active March 11, 2023 08:10
A deep comparison between two objects
function deepEqual(valueOne, valueTwo) {
if (typeof valueOne !== 'object' && typeof valueTwo !== 'object') {
const isValueOneNaN = isNaN(valueOne) && typeof valueOne === 'number';
const isValueTwoNan = isNaN(valueTwo) && typeof valueTwo === 'number';
if (isValueOneNaN && isValueTwoNan) return true;
return valueOne === valueTwo;
}
@shayphs
shayphs / cool-style-realtime.html
Last active March 11, 2023 07:59
You can edit the style in the browser itself and see the change happen there
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<style style="display: block;white-space: pre;" contenteditable="">