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
@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
@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) {
@Mazuh
Mazuh / blame_stats.sh
Created November 21, 2018 22:31
Script for reading stats for the git blames of Verto code over the years.
echo "Analyzing..."
for filename in ./*.js; do
total=`git blame $filename | wc -l`
echo "$filename"
for year in 2014 2015 2016 2017 2018; do
yearly=`git blame $filename | grep ".*$year-\d\d-\d\d.*" | wc -l`
percent=`expr 100 \* $yearly / $total`
tonys_yearly=`git blame $filename | grep ".*Anthony Minessale.*$year-\d\d-\d\d.*" | wc -l`
tonys_percent=`expr 100 \* $tonys_yearly / $total`
echo " $year: $yearly (yearly $percent% by everyone and $tonys_percent% by Anthony)"