Skip to content

Instantly share code, notes, and snippets.

View haikelfazzani's full-sized avatar
🎯
It's not a bug, it's a feature.

Haikel Fazzani haikelfazzani

🎯
It's not a bug, it's a feature.
View GitHub Profile
/*
reverse the string but without the index of the numbers.
Example: "he2llo" - "ol2leh"
Example: "De5ary4ou" - "uo5yra4eD"
Example: "D23amn5Boy" - "y23oBn5maD"
*/
reverseNoNumbers = (a) => (
v = a.match(/\D/g),
@haikelfazzani
haikelfazzani / flat-array.js
Last active September 2, 2019 20:04
flat array
// flat single level array
arr1.reduce((acc, val) => acc.concat(val), []);
// deep level flatten
function flatDeep(arr1) {
return arr1.reduce((acc, val) => Array.isArray(val) ? acc.concat(flatDeep(val)) : acc.concat(val), []);
};
//recursive flatten deep
function flatten(array) {
@haikelfazzani
haikelfazzani / array-map.js
Last active April 21, 2020 16:45
javascript array map method for old browser
function map(a, cb) {
var res = [];
for (var i = 0, l = a.length; i < l; i++) {
res.push(cb(a[i], i, a));
}
return res;
};
// Example :
@haikelfazzani
haikelfazzani / commands
Last active December 23, 2019 19:57
some windows commands (terminal) - rm, get get wifi password
-- your-WiFi-name
Netsh WLAN show interfaces
-- wifi password
netsh wlan show profile your-WiFi-name key=clear
-- remove folder
if exist folderName ( rmdir /s/q folderName )
or
rd /S nonemptydir
@haikelfazzani
haikelfazzani / integerToRoman.js
Last active September 12, 2019 23:23
Convert a number into a Roman Numeral
function integerToRoman(num) {
let o = {
M: 1000, CM: 900, D: 500, CD: 400,
C: 100, XC: 90, L: 50, XL: 40,
X: 10, IX: 9, V: 5, IV: 4, I: 1
}
let result = ''
Object.keys(o).map(i => {
while (num >= o[i]) {
result += i;
var months = [
"jan", "fév", "mars", "avril", "mai", "juin", "juil", "août", "sep", "oct", "nov", "déc"
]
var data = [
{ user: 'kim', createdAt: '2019-10-01' },
{ user: 'haikel', createdAt: '2019-11-01' },
{ user: 'james', createdAt: '2019-11-01' },
{ user: 'mike', createdAt: '2019-10-01' },
{ user: 'joe', createdAt: '2019-09-01' },
@haikelfazzani
haikelfazzani / useFetch.js
Last active November 4, 2022 00:19
useFetch React and Preact hook with AbortController
export default function useFetch (url, options) {
const [response, setResponse] = useState(null);
const [error, setError] = useState(null);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
const controller = new AbortController();
(async () => {
@haikelfazzani
haikelfazzani / animations.css
Created December 20, 2019 19:17
css animations
/* fadeIn */
@keyframes fadeIn {
from {
opacity: 0;
transform: scale(0);
}
to {
opacity: 1;
transform: scale(1);
```shell
sudo systemctl stop systemd-resolved
sudo systemctl disable systemd-resolved
sudo systemctl start resolvconf.service
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
sudo nano /etc/systemd/resolved.conf
cat /etc/resolv.conf
```