Skip to content

Instantly share code, notes, and snippets.

View erickvieira's full-sized avatar
👨‍🎓
Software Engineer - UFG 2021

Erick Vieira erickvieira

👨‍🎓
Software Engineer - UFG 2021
View GitHub Profile
#!/bin/bash
function format_bytes {
size=$1
size_in_bytes=$((size * 1024))
if [[ $(uname) == "Darwin" ]]; then
size_formatted=$(gnumfmt --to=iec-i --suffix=B --format="%.2f" "$size_in_bytes")
else
size_formatted=$(numfmt --to=iec-i --suffix=B --format="%.2f" -d "." "$size_in_bytes")
fi
@erickvieira
erickvieira / useSharedState.ts
Last active October 26, 2020 13:41
ReactJS Hook to create a RxJS based state and share it between React.FC components. No matters what level the state had been created, it will be available on whole app scope due to the BehaviorSubject. Read more about this approach here: https://medium.com/@thomasburlesonIA/https-medium-com-thomasburlesonia-react-hooks-rxjs-facades-4e116330bbe1 |
import { BehaviorSubject } from "rxjs"; // remember to install rxjs dependency
import { useCallback, useEffect, useState } from "react";
import { skip } from "rxjs/operators";
const globalSubject = new BehaviorSubject<any>({});
type SetSharedStateAction<S> = (state: S) => void;
export default function <T>(
subject: BehaviorSubject<T> = globalSubject
tune = "data:audio/mpeg;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU1LjEyLjEwMAAAAAAAAAAAAAAA//uQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAAcAAAAIAAAOsAA4ODg4ODg4ODg4ODhVVVVVVVVVVVVVVVVxcXFxcXFxcXFxcXFxjo6Ojo6Ojo6Ojo6OqqqqqqqqqqqqqqqqqsfHx8fHx8fHx8fHx+Pj4+Pj4+Pj4+Pj4+P///////////////9MYXZmNTUuMTIuMTAwAAAAAAAAAAAkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//uQRAAAAn4Tv4UlIABEwirzpKQADP4RahmJAAGltC3DIxAAFDiMVk6QoFERQGCTCMA4AwLOADAtYEAMBhy4rBAwIwDhtoKAgwoxw/DEQOB8u8McQO/1Agr/5SCDv////xAGBOHz4IHAfBwEAQicEAQBAEAAACqG6IAQBAEAwSIEaNHOiAUCgkJ0aOc/a6MUCgEAQDBJAuCAIQ/5cEAQOCcHAx1g+D9YPyjvKHP/E7//5QEP/+oEwf50FLgApF37Dtz3P3m1lX6yGruoixd2POMuGLxAw8AIonkGyqamRBNxHfz+XRzy1rMP1JHVDJocoFL/TTKBUe2ShqdPf+YGleouMo9zk////+r33///+pZgfb/8a5U/////9
// MIT License
// Copyright (c) 2020 Szabolcs Gelencsér
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@dabroder
dabroder / i3-gaps.sh
Created June 6, 2018 14:21
Install i3-gaps on ubuntu 18.04
#!/bin/bash
sudo apt install -y libxcb1-dev libxcb-keysyms1-dev libpango1.0-dev libxcb-util0-dev libxcb-icccm4-dev libyajl-dev libstartup-notification0-dev libxcb-randr0-dev libev-dev libxcb-cursor-dev libxcb-xinerama0-dev libxcb-xkb-dev libxkbcommon-dev libxkbcommon-x11-dev autoconf libxcb-xrm0 libxcb-xrm-dev automake
cd /tmp
# clone the repository
git clone https://www.github.com/Airblader/i3 i3-gaps
cd i3-gaps
# compile & install
@erickvieira
erickvieira / AlertType.kt
Last active May 8, 2018 20:28
[ANDROID][ALERTDIALOG][KOTLIN] An Android Native alert builder code: this code contains two classes that abstracts the usage of AlertDialog class in AndroidStudio projects. Obs.: The third file is an implementation example, it helps you to learn the right idealized usage.
// package com.example.user.project // REPLACE THIS LINE BY YOUR PACKAGE
import android.support.annotation.DrawableRes
import com.example.edmilton.prototipoamerica.R
enum class AlertType(@DrawableRes internal val path: Int) {
// THAT IS ONLY AN EXAMPLE, YOU CAN REPLACE WITH YOUR ICONS FILE NAMES
WARNING(R.drawable.ic_warning),
SUCCESS(R.drawable.ic_success),