Skip to content

Instantly share code, notes, and snippets.

View DouglasdeMoura's full-sized avatar

Douglas Moura DouglasdeMoura

View GitHub Profile
@DouglasdeMoura
DouglasdeMoura / vpn.sh
Created January 10, 2025 19:14
Connect to SSH server through VPN
#!/bin/bash
# Configuration variables - modify these
VPN_CONFIG="config.ovpn" # Set the path of the .ovpn file
SSH_HOST="0.0.0.0"
SSH_PORT="22"
SSH_USER="ubuntu"
LOCAL_PORT="2222" # Local port to forward SSH through
# Function to check if required commands exist
@DouglasdeMoura
DouglasdeMoura / create-git-aliases.sh
Last active October 23, 2024 16:23
Create git aliases that I like to use
# Git
alias g=git
alias ga='git add'
alias gaa='git add --all'
alias gb='git branch'
alias gc='git commit -m'
alias gcam='git commit -a -m'
alias gca='git commit --amend'
alias gca!='git commit --amend --no-verify'
@DouglasdeMoura
DouglasdeMoura / cashier.js
Last active April 25, 2024 18:17
Get the change for a given value and available coins
/**
* @link https://twitter.com/coproduto/status/1783128938149023804
* @param {Number} value The value to be converted into coins
* @param {Array<number>} coins The available coins
* @returns {Array<number>} The coins that make up the value
*/
export function getChangeOptions(value, coins) {
const sortedCoins = coins.slice().sort((a, b) => b - a)
const changeOptions = []
@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 August 11, 2024 20:22
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'