Skip to content

Instantly share code, notes, and snippets.

View jdgabriel's full-sized avatar
👋
console.log("Hello World")

Gabriel Duarte jdgabriel

👋
console.log("Hello World")
View GitHub Profile
@jdgabriel
jdgabriel / deep-partial.type.ts
Created December 23, 2024 02:06
Typescritp Utils
// DeepPartial with Mapped Types
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]>: T[P];
};
// Example
type User = {
name: string;
address: {
street: string;
@jdgabriel
jdgabriel / graph.md
Last active July 7, 2025 17:32
3 Types of Algorithms Every Programmer Needs to Know

Depth-First Search - O(n) / Matix/Vertice - O(n²)

function dfs(graph, start) {
  const stack = [start];
  const visited = new Set();
  const result = [];

  while (stack.length) {
    const vertex = stack.pop();
@jdgabriel
jdgabriel / multiple-refs.ts
Created January 24, 2024 13:28
Multiple ref - React
import { type MutableRefObject, type RefCallback } from 'react';
type MutableRefList<T> = Array<RefCallback<T> | MutableRefObject<T> | undefined | null>;
export function mergeRefs<T>(...refs: MutableRefList<T>): RefCallback<T> {
return (val: T) => {
setRef(val, ...refs);
};
}
@jdgabriel
jdgabriel / settings.json
Last active November 10, 2023 14:28
VSCode Settings
{
// Editor Configurations
"editor.fontSize": 12,
"editor.fontFamily": "Fira Code",
"editor.rulers": [100,130],
"editor.tabSize": 2,
"editor.parameterHints.enabled": false,
"editor.renderLineHighlight": "gutter",
"editor.lineHeight": 26,
"editor.suggestSelection": "first",
@jdgabriel
jdgabriel / .zshrc
Last active August 20, 2024 19:11 — forked from callumlocke/.zshrc
ZSH function to auto-switch to correct Node version
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
#Add .NET to $PATH
export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools
@jdgabriel
jdgabriel / index.js
Created August 24, 2023 18:12 — forked from LindaLawton/index.js
Example for downloading a file from google drive api using Node.js
// npm install googleapis@105 @google-cloud/[email protected] --save
const fs = require('fs');
const fsp = fs.promises;
const path = require('path');
const process = require('process');
const {authenticate} = require('@google-cloud/local-auth');
const {google} = require('googleapis');
@jdgabriel
jdgabriel / MyComponent.js
Created August 21, 2023 22:14
Switch case - React
import { Switch, Case, Default } from '@/components/conditional-switch'
export default function MyComponent({ goal }) {
return (
<Switch>
<Case conditional={goal < 30}>Case 1</Case>
<Case conditional={goal >= 30}>Case 2</Case>
<Case conditional={goal >= 60}>Case 3</Case>
<Default>Default Case</Default>
</Switch>
@jdgabriel
jdgabriel / calendar_code.js
Created January 21, 2022 20:43
Calendar with MomentJS
const moment = require("moment");
const fs = require("fs");
let calendar = [];
const today = moment();
const startDay = today.clone().startOf("month").startOf("week");
const endDay = today.clone().endOf("month").endOf("week");
let date = startDay.clone().subtract(1, "day");
@jdgabriel
jdgabriel / network_wsl2.ps1
Created July 26, 2021 11:05
Habilitar WSL na rede e localhost
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ){
$remoteport = $matches[0];
} else{
echo "The Script Exited, the ip address of WSL 2 cannot be found";
exit;
}
@jdgabriel
jdgabriel / docker-mysql.txt
Last active July 9, 2021 10:28
Docker MySQL
docker run -d --name database-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -e TZ=America/Sao_Paulo mysql:5.7.31 --default-authentication-plugin=mysql_native_password --sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER --explicit_defaults_for_timestamp