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 / find_node_modules.sh
Created July 11, 2022 12:03
Scripts to clean multiple node_modules recursively.
find . -name 'node_modules' -type d -prune
function getBgColor(variant) {
if (variant === "primary") {
return "blue";
}
if (variant === "danger") {
return "red";
}
if (variant === "warning") {
interface User {
name: string;
age: number;
}
interface AuthorizedUser extends User {
token: string;
}
type UserDisplayProps = { user: User };
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