This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type AtLeastOnePropertyOf<T, K extends keyof T> = K extends K ? Record<K, T[K]> : never | |
type User = { | |
name: string; | |
age: number; | |
} | |
type UpdateUser = AtLeastOnePropertyOf<User, keyof User> & Partial<User> | |
const user = { | |
name: 'name', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ExactlyOne<T> = { | |
[K in keyof T]: Pick<T, K> & Partial<Record<Exclude<keyof T, K>, never>> | |
}[keyof T] | |
type User = { | |
name: string; | |
age: number; | |
} | |
function updateExactlyOne(user: User, newUser: ExactlyOne<User>) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -ne 1 ]; then | |
echo "Uso: $0 PORTA" | |
exit 1 | |
fi | |
PORTA=$1 | |
PIDS=$(sudo lsof -t -i:$PORTA) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const re = /(?<name>\w+)\s(?<age>\d+)/; | |
const matches = re.exec('John 30'); | |
const [match, name, age] = re.exec('John 30'); // ['John 30', 'John', '30'] | |
console.log(matches.groups); // { name: 'John', age: '30' } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const navigateBack = () => history.back(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const searchWord = (text: string, wordToSearchInText: string): boolean => text.includes(wordToSearchInText) |