Skip to content

Instantly share code, notes, and snippets.

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

Marcell Guilherme Costa da Silva Mazuh

👨‍💻
Code Summoner
View GitHub Profile
function getBgColor(variant) {
if (variant === "primary") {
return "blue";
}
if (variant === "danger") {
return "red";
}
if (variant === "warning") {
import { useState } from "react";
export default function App() {
const [people, setPeople] = useState([]);
const handleSubmit = (event) => {
event.preventDefault();
setPeople([...people, event.target.person.value]);
event.target.reset();
};
@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
Created March 21, 2019 14:22
Cleaning all git branches, except the master, in the current repository directory.
git branch | grep -v "master" | xargs git branch -D