Skip to content

Instantly share code, notes, and snippets.

View Mazuh's full-sized avatar
👨‍💻
Code Summoner

Marcell Mazuh

👨‍💻
Code Summoner
View GitHub Profile
@Mazuh
Mazuh / gist:a58e5bd48fdb365fba85b3636e30a383
Created February 15, 2021 21:54
firestore simple rule
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, delete:
if request.auth != null && request.auth.uid == resource.data.userUid;
allow create, update:
if request.auth != null && request.auth.uid == request.resource.data.userUid;
}
}
@Mazuh
Mazuh / ls-dangling-volumes.sh
Last active August 12, 2020 13:01
Clear Docker artifacts.
docker volume ls -q -f dangling=true
@Mazuh
Mazuh / usePrevious.js
Created May 7, 2020 11:49
usePrevious hook for React to track data changes between renderings
import React from 'react';
export default function usePrevious(value) {
const ref = React.useRef();
React.useEffect(() => {
ref.current = value;
}, [value]);
return ref.current;
@Mazuh
Mazuh / rm-docker-dangling-volumes.sh
Created April 16, 2020 05:00
Remove all Docker dangling volumes
docker volume rm `docker volume ls -q -f dangling=true`
@Mazuh
Mazuh / tasks-crud-local-storage.js
Created March 7, 2020 13:07
CRUD for tasks on local storage.
import { v4 as uuidv4 } from 'uuid';
const TASKS_KEY = 'tasks';
export const retrieveTasks = () => {
const serialized = localStorage.getItem(TASKS_KEY);
const tasks = serialized ? JSON.parse(serialized) : [];
return tasks;
};
@Mazuh
Mazuh / applyToQueuedPromises.js
Last active November 29, 2019 13:26
Queued Promises maker
import chunk from 'lodash/chunk';
/**
*
* Util to map values to `Promise`s and invoke them in queue order,
* being assured each `Promise` is resolved before the next be created.
*
* It reduces `data` array to a `Promise` which is the accumulated chain
* of async tasks resulting of each element mapped thru `asyncIteratee`.
* As a chain, each `asyncIteratee` follows a queue order of call, and
@Mazuh
Mazuh / clean_pyc_files.sh
Created April 24, 2019 19:05
Clean .pyc files from current subdirectories
find . -name '*.pyc' -delete
@Mazuh
Mazuh / clean_branchs.sh
Last active August 21, 2024 13:31
Cleaning all git branches, except the master, in the current repository directory.
git branch | grep -v "main" | xargs git branch -D
@Mazuh
Mazuh / sdp-handler.js
Last active March 21, 2019 14:20
Functional and pure helper to assure video comes first on SDP media lines (tho not so pragmatic). Forked from: https://gist.github.com/edolix/73b2e085104250691a421b8f3678c86c
export function reorderSdpMediaLines(sdp) {
const lineBreaker = '\r\n';
const parsed = sdp.split(lineBreaker).reduce((parser, line) => {
const reading = (line.startsWith('m=video') && 'video')
|| (line.startsWith('m=audio') && 'audio')
|| parser.reading;
if (line === '') {
return parser;
}
@Mazuh
Mazuh / compact-object.js
Last active September 22, 2022 07:21
Remove all empty objects and undefined values from a nested object -- an enhanced and vanilla version of Lodash's `compact`.
function compactObject(data) {
if (typeof data !== 'object') {
return data;
}
return Object.keys(data).reduce(function(accumulator, key) {
const isObject = typeof data[key] === 'object';
const value = isObject ? compactObject(data[key]) : data[key];
const isEmptyObject = isObject && !Object.keys(value).length;
if (value === undefined || isEmptyObject) {