Skip to content

Instantly share code, notes, and snippets.

View igolskyi's full-sized avatar
🇺🇦

Yurii Holskyi igolskyi

🇺🇦
View GitHub Profile
@igolskyi
igolskyi / useUrlHash.ts
Created August 5, 2024 14:14
React, Next.js hook that lets you subscribe to 'hashchange' event of window.
import { useSyncExternalStore } from 'react';
const subscribe = (cb: () => void) => {
window.addEventListener('hashchange', cb);
return () => {
window.removeEventListener('hashchange', cb);
};
};
@igolskyi
igolskyi / gist:8e566c81583cb065058454b1017158e0
Last active May 28, 2024 07:42
Loop through folders and execute commands: git pull -> if has updates -> npm i; npm run migrate (if has .sequelizerc)
#!/bin/bash
# Get the current directory
projects=$(pwd)
# Loop through each project folder in the current directory
for project in "$projects"/*; do
if [ -d "$project" ]; then
project=$(basename "$project")
echo "******************************************************************************"
** dump to file **
pg_dump -h localhost -U postgres -F p acl > ./acl.sql
** or dump to .tar archieve **
pg_dump -h localhost -U db_user -W -F t db_name > /path/to/acl.tar
** restore dump **
pg_restore -h localhost -U postgres -c -d "acl" ./path/to/acl.tar