Skip to content

Instantly share code, notes, and snippets.

View luiznasciment0's full-sized avatar
💻
coding

Luiz Nascimento luiznasciment0

💻
coding
View GitHub Profile
@luiznasciment0
luiznasciment0 / omitKeys.ts
Last active June 29, 2021 02:36
omitKeys
const cloneObject = <TObject extends { [key: string]: unknown }>(object: TObject): TObject =>
JSON.parse(JSON.stringify(object))
/*
* Essa função serve para remover propriedades de um objeto sem a necessidade de fazer mutações
* Dessa forma, você não perde a referência do objeto original se precisar utilizá-lo posteriormente
*
*
@param
object - O objeto que você quer remover uma propriedade.
*
@luiznasciment0
luiznasciment0 / useKeyPress.ts
Last active July 15, 2021 08:16
hook to detect keyboard key pressed and execute an action when this key is pressed
import { useEffect } from 'react'
type KeyPress = {
key: string
action: () => void
}
const useKeyPress = ({ key, action }: KeyPress) => {
const onKeyDown = (e: KeyboardEvent) => {
if (e.key === key) action()
@luiznasciment0
luiznasciment0 / tutorial.txt
Created November 27, 2021 18:05
website to download fonts
url: https://google-webfonts-helper.herokuapp.com/
download the font you want to use, remove the .woff files, leaving only the .woff2 ones.
Create a /fonts folder in the /public folder and put the .woff2 files there
then, in your global styles, you add this (just an example):
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
@luiznasciment0
luiznasciment0 / main.js
Created December 9, 2021 20:22
storybook + typescript: how to setup path aliases in storybook, just as you did on your tsconfig file
/* first of all, install "tsconfig-paths-webpack-plugin" */
/* yarn add --dev tsconfig-paths-webpack-plugin */
/* then, integrate it with storybook's default main.js configuration */
// before:
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
framework: '@storybook/react',
@luiznasciment0
luiznasciment0 / select.css
Created December 14, 2021 04:45
how to make select element to work cross browser
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;
background-color: #fff;
background-image: url('data:image/svg+xml;charset=US-ASCII,<svg%20xmlns%3D"http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg"%20width%3D"292.4"%20height%3D"292.4"><path%20fill%3D"%23000000"%20d%3D"M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z"%2F><%2Fsvg>');
background-repeat: no-repeat, repeat;
background-position: right 0.7em top 50%, 0 0;
background-size: 0.65em auto, 100%;
@luiznasciment0
luiznasciment0 / fizzBuzz.js
Created December 16, 2021 20:21
how I usually solve fiz buzz hacker rank challenge
/*
* Complete the 'fizzBuzz' function below.
*
* The function accepts INTEGER n as parameter.
*/
function fizzBuzz(n) {
for (let i = 1; i <= n; i++) {
// const isMultipleOfThreeAndFive = i % 3 === 0 && i % 5 === 0;
const isMultipleOfThreeOnly = i % 3 === 0 && i % 5 !== 0;
curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data
source: https://gist.github.com/subfuzion/08c5d85437d5d4f00e58
function getKeysToBeRemoved(key) {
const hasDot = key.includes('.');
if (!hasDot) {
return [key];
}
const [key1, key2] = key.split('.');
return [key1, key2];
}
function removePropsFromObject(_obj, keysToRemove) {
@luiznasciment0
luiznasciment0 / challenge.rb
Last active February 7, 2022 02:29
My first Ruby challenge :)
#
# MP: Matches Played
# W: Matches Won
# D: Matches Drawn (Tied)
# L: Matches Lost
# P: Points
#
# output expected:
# Team | MP | W | D | L | P
# Devastating Donkeys | 3 | 2 | 1 | 0 | 7
import React from "react";
type Status = "idle" | "pending" | "resolved" | "rejected";
interface RequestState<DataType> {
data: DataType | null;
status: Status;
error: unknown;
}