Skip to content

Instantly share code, notes, and snippets.

View brunobertolini's full-sized avatar
🎯
Focusing

Bruno Bertolini brunobertolini

🎯
Focusing
View GitHub Profile
@brunobertolini
brunobertolini / use-storage.js
Created January 15, 2024 13:48
A react useState with localStorage persistence
import { useEffect, useState } from 'react'
export const useStorage = (key, defaultValue) => {
const [value, setValue] = useState(() => {
const storedValue = typeof window !== 'undefined' && window?.localStorage.getItem(key)
return (storedValue && JSON.parse(storedValue)[key]) || defaultValue
})
useEffect(() => {
const valueToStore = { [key]: value }
[
{
"gameTime": "2022-11-20T16:00:00Z",
"homeTeam": "cat",
"awayTeam": "equ"
},
{
"gameTime": "2022-11-21T13:00:00Z",
"homeTeam": "ing",
"awayTeam": "ira"
@brunobertolini
brunobertolini / safari-flex-gap-polyfill.css
Created December 8, 2021 14:30
A Flex Gap polyfill to old Safari versions using Tailwind
@supports (-webkit-touch-callout: none) {
.gap-2.flex:not(.flex-col):not(.flex-wrap) > *:not(:last-child) {
margin-right: 0.5rem;
}
.gap-3.flex:not(.flex-col):not(.flex-wrap) > *:not(:last-child) {
margin-right: 0.75rem;
}
.gap-4.flex:not(.flex-col):not(.flex-wrap) > *:not(:last-child) {
{
"editor.suggestSelection": "first",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"github.copilot.enable": {
"yaml": false,
"*": true,
"plaintext": true,
"markdown": false
SPACESHIP_PROMPT_ORDER=(
user # Username section
dir # Current directory section
host # Hostname section
git # Git section (git_branch + git_status)
exec_time # Execution time
line_sep # Line break
vi_mode # Vi-mode indicator
jobs # Background jobs indicator
exit_code # Exit code section
@brunobertolini
brunobertolini / vscode.keybindings.json
Last active February 27, 2021 13:34
vscode-terminal
// Empty
[
{
"key": "cmd+k cmd+o",
"command": "workbench.action.addRootFolder"
},
{
"key": "cmd+j",
"command": "workbench.action.toggleMaximizedPanel",
"when": "!terminalFocus"
[alias]
k = !gitk --all &
dismiss = reset HEAD --hard
rollback = reset --soft HEAD~1
unstage = reset HEAD --
undo = checkout --
redo = commit --amend --no-edit
sane = remote prune origin
send = push origin $(git rev-parse --abbrev-ref HEAD)
l = log --graph --pretty=format:'%C(yellow)%h%Creset %Cgreen%cr %C(bold blue)%an%Creset - %s%C(red)%d%Creset' --abbrev-commit --max-count=30
import * as R from 'ramda'
export const between = (num: number, min: number, max: number) =>
R.max(min, R.min(num, max))
export const paginate = (
records: number,
limit: number = 10,
current: number = 1,
delta: number = 1,
@brunobertolini
brunobertolini / .env
Last active August 7, 2018 19:44
Instance setup scripts
#!/bin/bash
@brunobertolini
brunobertolini / flexbox.js
Last active February 27, 2018 17:29
Based on https://gist.github.com/jorilallo/a9e60b3ce3f7373e3c65a50d65e8e1e8 with propTypes instead of Flow, and using styled-by
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import styledBy from 'styled-by'
const GlobalCssValues = ['initial', 'inherit', 'unset']
const WrapValue = ['nowrap', 'wrap', 'wrap-reverse', ...GlobalCssValues]
const JustifyValue = [
'center',
'start',