Skip to content

Instantly share code, notes, and snippets.

View elshanx's full-sized avatar
🚀
always learning

Elshan Alkhabaz elshanx

🚀
always learning
View GitHub Profile
@elshanx
elshanx / extension.txt
Created December 20, 2023 00:47
vscode extensions
aaron-bond.better-comments
AbhijoyBasak.nestjs-files
atomiks.moonlight
bradlc.vscode-tailwindcss
BriteSnow.vscode-toggle-quotes
Cardinal90.multi-cursor-case-preserve
cipchk.cssrem
DavidAnson.vscode-markdownlint
devine-davies.make-hidden
eamodio.gitlens
@elshanx
elshanx / gist:7ec5961feccca17dce81f388227a1706
Created October 11, 2023 08:41
recover dropped stashes
git fsck --unreachable | grep commit | cut -d" " -f3 | xargs git log --merges --no-walk --grep=WIP
// WIP is for unnamed stashes, if you named your stash then you can find it with grep
@elshanx
elshanx / updateTranslations.js
Created September 25, 2023 09:48
Nodejs script for updating Angular i18n json files in CLI
// Usage example:
// node updateTranslations.js COMMON are_you_sure "Are you sure?" az,en,ru
// or
// node updateTranslations.js COMMON are_you_sure "Are you sure?" // this will update all three languages. it's the same as above
const fs = require("fs");
const path = require("path");
// Get command-line arguments
const args = process.argv.slice(2);
@elshanx
elshanx / test.script.js
Created July 27, 2023 14:00
[Postman] Store access token automatically on [register, login] routes
if (pm.response.code !== 200) {
return;
}
const response = pm.response.json(),
accessToken = response.data.token;
// Storing the access token in the environment to be used in other endpoints
pm.collectionVariables.set('accessToken', accessToken);
@elshanx
elshanx / tests.yml
Created November 29, 2021 14:09
github workflow for running tests on push and PRs
name: Node.js CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
@elshanx
elshanx / custom-logger.ts
Last active November 24, 2021 15:01
custom redux logger middleware with toggle functionality
import type { Middleware } from 'redux'
import { logger } from 'redux-logger'
const customLogger: Middleware = (api) => (next) => (action) => {
if (window.__REDUX_LOGGER__) return logger(api)(next)(action)
return next(action)
}
export default customLogger
@elshanx
elshanx / integrate.yml
Created November 21, 2021 14:57
Github action for PRs to check if it builds without errors before merging to main
name: Node Continuous Integration
on:
pull_request:
branches: [ main ]
jobs:
test_pull_request:
runs-on: ubuntu-latest
@elshanx
elshanx / .js
Created November 14, 2021 00:50
syntax highlighting for json objects in DOM
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
let cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
@elshanx
elshanx / Select.tsx
Last active November 18, 2021 19:29
a custom accessible typed select in react with react-hook-form and refs
import type { KeyboardEvent } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import type { FieldError, Path, UseFormClearErrors, UseFormSetValue } from 'react-hook-form'
import OutsideClickHandler from 'react-outside-click-handler'
import styled from 'styled-components'
import InputError from '@/components/shared/InputError'
type SelectOption = {
value: string
@elshanx
elshanx / .ts
Created October 13, 2021 18:00
ts utils
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never }
export type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U