Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Code Summoner

Marcell Guilherme Costa da Silva Mazuh

👨‍💻
Code Summoner
View GitHub Profile
View isp.tsx
function getBgColor(variant) {
if (variant === "primary") {
return "blue";
}
if (variant === "danger") {
return "red";
}
if (variant === "warning") {
View liskov-abuse.tsx
interface User {
name: string;
age: number;
}
interface AuthorizedUser extends User {
token: string;
}
type UserDisplayProps = { user: User };
View single-responsibilty-broken.js
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();
};
View gist:a58e5bd48fdb365fba85b3636e30a383
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 Aug 12, 2020
Clear Docker artifacts.
View ls-dangling-volumes.sh
docker volume ls -q -f dangling=true
@Mazuh
Mazuh / usePrevious.js
Created May 7, 2020
usePrevious hook for React to track data changes between renderings
View usePrevious.js
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 Apr 16, 2020
Remove all Docker dangling volumes
View rm-docker-dangling-volumes.sh
docker volume rm `docker volume ls -q -f dangling=true`
@Mazuh
Mazuh / tasks-crud-local-storage.js
Created Mar 7, 2020
CRUD for tasks on local storage.
View tasks-crud-local-storage.js
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 Nov 29, 2019
Queued Promises maker
View applyToQueuedPromises.js
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 Apr 24, 2019
Clean .pyc files from current subdirectories
View clean_pyc_files.sh
find . -name '*.pyc' -delete