Skip to content

Instantly share code, notes, and snippets.

View noxd3v's full-sized avatar
🏠
Working from home

noxd3v noxd3v

🏠
Working from home
View GitHub Profile
@noxd3v
noxd3v / Busy port 3000.md
Last active February 15, 2023 11:27
Various Windows commands

Something else is already running on port 3000

Find which process is using port and kill it

netstat -ano | findstr :3000 taskkill /PID [pid number] /F

if this doesn't work stop WinNAT service first (admin elevation required)

net stop winnat

@noxd3v
noxd3v / configuration.js
Last active April 26, 2022 14:28
Apollo Server
const path = require("path");
const { makeExecutableSchema } = require("@graphql-tools/schema");
const { loadFilesSync } = require("@graphql-tools/load-files");
const { mergeTypeDefs, mergeResolvers } = require("@graphql-tools/merge");
const { DateResolver } = require("graphql-scalars");
const typesArr = loadFilesSync(path.join(__dirname, "./graphql"), {
extensions: ["graphql"],
recursive: true,
});
@noxd3v
noxd3v / iterator.js
Last active April 7, 2022 12:14
Javascript snippets.js
const items = [1, true, { name: "John" }, [1, 2, 3], 1.5];
function Iterator(collection) {
this.items = collection;
this.index = 0;
}
Iterator.prototype = {
hasNext: function () {
return this.index < this.items.length;
function getObjectKeyValue(obj, key) {
let path = [];
const getPath = (obj, key) => {
return Object.keys(obj).reduce((acc, k) => {
if (typeof obj[k] === "object" && obj[k] !== null) {
path.push(k);
getPath(obj[k], key);
}
return acc;
}, []);
@noxd3v
noxd3v / fibonacci.js
Last active September 25, 2021 16:25
Codewars
const productFib = (prod) => {
let n = 0;
let c = 1;
while (n * c < prod) {
n += c;
c = n - c;
}
return [n, c, n * c === prod];
};
@noxd3v
noxd3v / index.js
Last active January 3, 2024 12:10
Change dayjs locale dynamically
const locales = {
bs: import("dayjs/locale/hr"),
de: import("dayjs/locale/de"),
};
const setDayJsLocale = (language) => {
locales[language].then(() => {
/* bs uses default english, so we transform to closest one */
const altLang = language === "bs" ? "hr" : language;
dayjs.locale(altLang);
@noxd3v
noxd3v / style.md
Last active August 31, 2021 05:44
Airbnb style guide

Arrays

// good
[1, 2, 3].map((x) => {
  const y = x + 1;
  return x * y;
});

// good
@noxd3v
noxd3v / test CORS.md
Last active August 5, 2021 10:05
How to test CORS with curl

curl -H "Access-Control-Request-Method: GET" -H "Origin: http://localhost" --head http://www.example.com/

  1. Replace http://www.example.com/ with URL you want to test.
  2. If response includes Access-Control-Allow-* then your resource supports CORS.

Link

@noxd3v
noxd3v / email-recycler.md
Last active July 15, 2021 09:27
Create email recycler on cPanel using cron job

Create script in your home directory

#!/bin/sh
find /home2/hna7u7/mail/domain/username/new -mtime +180 -type f -ls -delete
find /home2/hna7u7/mail/domain/username/cur -mtime +180 -type f -ls -delete

This script will delete all files from new and cur older than 180 days. Now add cron job to execute the command

@noxd3v
noxd3v / basics.MD
Last active March 10, 2021 17:45
Docker commands

Reference

This will build an image with name react-image docker build -t react-image .

docker image ls

Run image and bind the port to 3000 to redirect traffic

docker run -e CHOKIDAR_USEPOLLING=true -v %cd%\src:/app/src:ro -d -p 3000:3000 --name react-app react-image