Skip to content

Instantly share code, notes, and snippets.

View MertHaddad's full-sized avatar
🎯
Focusing

Mert Haddad MertHaddad

🎯
Focusing
  • Huawei
  • Istanbul
View GitHub Profile
@MertHaddad
MertHaddad / dockerCheatSheet
Last active December 29, 2022 09:30
dockerCheatSheet
How to push an image to Docker Hub?
//get the images:
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
verse_gapminder_gsl latest 023ab91c6291 3 minutes ago 1.975 GB
verse_gapminder latest bb38976d03cf 13 minutes ago 1.955 GB
rocker/verse latest 0168d115f220 3 days ago 1.954 GB
//give a tag name:
@MertHaddad
MertHaddad / use https with json-server
Created November 27, 2022 14:14
use https with json-server
Create your cert
openssl req -nodes -new -x509 -keyout server.key -out server.cert
// https-json-server.js
import jsonServer from 'json-server';
import https from 'https';
import path from 'path';
import fs from 'fs';
const server = jsonServer.create();
@MertHaddad
MertHaddad / enterBiosUsingCMD
Created October 6, 2022 11:58
Enter Bios Using CMD
shutdown /r /fw /f /t 0
@MertHaddad
MertHaddad / findUpdateObjectInArray
Created August 9, 2022 05:07
How can I find and update values in an array of objects?
You can use findIndex to find the index in the array of the object and replace it as required:
var item = {...}
var items = [{id:2}, {id:2}, {id:2}];
var foundIndex = items.findIndex(x => x.id == item.id);
items[foundIndex] = item;
This assumes unique IDs. If your IDs are duplicated (as in your example), it's probably better if you use forEach:
items.forEach((element, index) => {
@MertHaddad
MertHaddad / array.includes(object)Alternative
Created August 8, 2022 12:00
array includes with Object - Alternative
Array.includes compares by object identity just like obj === obj2, so sadly this doesn't work unless the two items are references to the same object.
You can often use Array.prototype.some() instead which takes a function:
const arr = [{a: 'b'}]
console.log(arr.some(item => item.a === 'b'))
@MertHaddad
MertHaddad / lastDigitOfNum
Created June 28, 2022 11:27
get the last digit of a number
console.log(Number(String(num).slice(-1)))
@MertHaddad
MertHaddad / reverseString
Created June 26, 2022 14:28
fastest way to reverse a string in JavaString
let string = "hello";
let newString = ""
var i = string.length;
while(i--)newString += string[i]
@MertHaddad
MertHaddad / arraysIntersection
Created June 15, 2022 13:51
intersectin betwen 2 arrays
const filteredArray = array1.filter(value => array2.includes(value));
@MertHaddad
MertHaddad / screenDimensionHook
Created June 12, 2022 06:38
get screen dimension ReactJS
function getWindowDimensions() {
const { innerWidth: width, innerHeight: height } = window;
return {
width,
height
};
}
@MertHaddad
MertHaddad / getUniqueValuesES6
Created June 9, 2022 07:14
Get all unique values in a JavaScript array ES6
var myArray = ['a', 1, 'a', 2, '1'];
let unique = [...new Set(myArray)];
console.log(unique); // unique is ['a', 1, 2, '1']