Skip to content

Instantly share code, notes, and snippets.

View DouglasdeMoura's full-sized avatar

Douglas Moura DouglasdeMoura

View GitHub Profile
@DouglasdeMoura
DouglasdeMoura / is-balanced.js
Created April 22, 2024 16:37
Check if a string is balanced
/**
* Check if given string is balanced, i.e., if it has the same number of open and close delimiters.
* The following delimiters are considered: '(', ')', '[', ']', '{', '}'.
* A string with no delimiters is considered balanced.
*
* @link https://twitter.com/coproduto/status/1782352142050775113
* @param str {String} to check if it is balanced
* @returns {Boolean}
*/
export function isBalanced(str) {
@DouglasdeMoura
DouglasdeMoura / jokenpo.ts
Created December 27, 2023 16:30
Jokenpo in TypeScript
type Moves = "rock" | "paper" | "scissors";
type RockPaperScissors<_Move extends Moves> = _Move extends "rock"
? "paper"
: _Move extends "paper"
? "scissors"
: "rock";
type Result = RockPaperScissors<"rock">; // expected to be 'paper'
@DouglasdeMoura
DouglasdeMoura / api.ts
Last active April 1, 2024 15:00
Tiny wrapper around fetch
// Extends the return of the HTTPError class
class HTTPError extends Error {
readonly response: any;
readonly status: number;
readonly statusText: string;
constructor(status: number, statusText: string, response: any) {
super(statusText);
this.status = status;
this.statusText = statusText;
@DouglasdeMoura
DouglasdeMoura / pocketbase.yml
Created January 30, 2023 17:34
Pocketbase 0.12
captainVersion: 4
services:
'$$cap_appname':
caproverExtra:
dockerfileLines:
- FROM alpine:3.16.2
- RUN apk add --no-cache unzip openssh
- ADD https://github.com/pocketbase/pocketbase/releases/download/v$$cap_version/pocketbase_$$cap_version_linux_amd64.zip /tmp/pb.zip
- RUN unzip /tmp/pb.zip -d /pb/
@DouglasdeMoura
DouglasdeMoura / baserow.yml
Last active December 8, 2022 13:16
Baserow definition file for CapRover
captainVersion: 4
version: '3.3'
services:
$$cap_appname:
container_name: $$cap_appname
environment:
BASEROW_PUBLIC_URL: http://$$cap_appname.$$cap_root_domain
volumes:
- $$cap_appname-data:/baserow/data
restart: unless-stopped
@DouglasdeMoura
DouglasdeMoura / responsive-images.css
Last active September 7, 2022 16:53
Como criar placeholders bonitos para suas imagens
/* Tornando todas as imagens do site responsivas */
img {
width: 100%;
height: auto;
}
@DouglasdeMoura
DouglasdeMoura / README.md
Created July 6, 2022 20:52 — forked from nikoheikkila/README.md
Fish Shell function for sourcing standard .env files

envsource

I've been using Fish shell for years which is great and all, but one thing that has got me frustrated is using it with .env files.

When attempting to run source .env in a project, I usually encounter this problem:

.env (line 2): Unsupported use of '='. In fish, please use 'set KEY value'.
from sourcing file .env
source: Error while reading file '.env'
@DouglasdeMoura
DouglasdeMoura / quotes
Last active June 24, 2022 23:45
Quote for my random quotes generator
[
{
"text": "Life isn’t about getting and having, it’s about giving and being.",
"author": "Kevin Kruse"
},
{
"text": "Whatever the mind of man can conceive and believe, it can achieve.",
"author": "Napoleon Hill"
},
{
@DouglasdeMoura
DouglasdeMoura / .eslintrc.js
Created March 29, 2022 16:12
My ESLint config
module.exports = {
env: {
browser: true,
node: true,
},
settings: {
react: {
version: 'detect',
},
node: {
@DouglasdeMoura
DouglasdeMoura / input.spec.tsx
Last active February 15, 2022 11:31
Simple React Input validation
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { Input } from '.'
describe('<Input />', () => {
it('should render the component', () => {
render(<Input label="mock_label" />)
expect(screen.getByLabelText('mock_label')).toBeInTheDocument()