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 / equals-pm.ex
Created April 16, 2024 12:06
Elixir example of pattern matching for equal values
defmodule Comp do
def equals?(same, same), do: true
def equals?(one, another), do: false
end
IO.inspect Comp.equals?(4, 2)
# false
IO.inspect Comp.equals?(42, 42)
# true
@Mazuh
Mazuh / maybe.py
Created January 23, 2024 03:14
Maybe in Python.
class Maybe:
condition_fn = None
then_fn = None
otherwise_fn = None
def __init__(self, condition_fn):
self.condition_fn = condition_fn
def then(self, then_fn):
self.then_fn = then_fn
@Mazuh
Mazuh / opfs.ts
Created January 23, 2024 00:09
Basic OPFS adapter in TS.
interface OpfsAdapter<T> {
persist: (data: T) => Promise<void>;
retrieve: () => Promise<T | null>;
}
export async function makeOpfsAdapter<T>(filename: string): Promise<OpfsAdapter<T>> {
const opfsRoot = await navigator.storage.getDirectory();
const directoryHandle = await opfsRoot.getDirectoryHandle("my_pretty_stuff", {
create: true,
@Mazuh
Mazuh / .zshrc
Created August 13, 2023 19:45
"NVM use" after entering each directory
# Run 'nvm use' automatically every time there's
# a .nvmrc file in the directory. Also, revert to default
# version when entering a directory without .nvmrc
#
enter_directory() {
if [[ $PWD == $PREV_PWD ]]; then
return
fi
PREV_PWD=$PWD
@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 / find_node_modules.sh
Created July 11, 2022 12:03
Scripts to clean multiple node_modules recursively.
find . -name 'node_modules' -type d -prune
@Mazuh
Mazuh / .gitlab-ci.yml
Last active May 13, 2022 04:53
Example of gitlab CI/CD for a create-react-app application on Amazon S3 Bucket.
image: nikolaik/python-nodejs:latest
stages:
- install
- test
- deploy
prodInstall:
stage: install
script:
interface User {
name: string;
age: number;
}
interface AuthorizedUser extends User {
token: string;
}
type UserDisplayProps = { user: User };
@Mazuh
Mazuh / infobus_data.json
Last active March 7, 2021 00:34
Digital version of UFRN's bus departure times and some other metadata for InfoBus clients. Check InfoBus-UFRN repository for more details: <https://github.com/Mazuh/InfoBusUFRN-App>.
{
"meta": {
"supportedMobileVersions": [
"2.0.0", "2.2.0"
]
},
"content": {
"mobileMessage": {
"title": "Fique seguro(a)!",
"isAnEmergency": true,
function getBgColor(variant) {
if (variant === "primary") {
return "blue";
}
if (variant === "danger") {
return "red";
}
if (variant === "warning") {