Skip to content

Instantly share code, notes, and snippets.

View mtt87's full-sized avatar
🍔

Mattia mtt87

🍔
View GitHub Profile

Following this discussion on Twitter https://twitter.com/mattia_asti/status/1645517258926575616 I found out that the current pattern we are using for react-query custom hooks is bad.

// BAD
function useAnimalsBad() {
  const { data, isFetching, refetch } = useQuery<Animal[]>(
    ["animals-bad"],
    () => getAnimals()
  );
@mtt87
mtt87 / setup.md
Created March 5, 2023 16:06
Philips Hue Sync box issues

Setup before

LG OLED55C14LB (4k resolution)

  • HDMI1 PS5
  • HDMI2 (eARC enabled) AppleTV 4k latest gen ethernet

I also have 2x HomePods gen2 connected to AppleTV Both cables are HDMI 2.1 8k certified cable, and I can watch Dolby Vision content without any issues, hear sound with no issues and since eARC is enabled on the AppleTV I can hear the sound of PS5 through the HomePods when I play games.

Setup after adding Hue sync box + Hue smart light gradient for 55" tv

@mtt87
mtt87 / _middleware.ts
Created December 21, 2021 14:39
Add password protection to any Vercel website, save $150/month.
import { addYears } from 'date-fns'
import { NextRequest, NextResponse } from 'next/server'
function middleware(req: NextRequest) {
if (req.nextUrl.pathname.startsWith('/api')) {
return NextResponse.next()
}
if (process.env.VERCEL_ENV !== 'preview') {
return NextResponse.next()
import Box from '@components/ui/Box'
import Flex from '@components/ui/Flex'
import Spinner from '@components/ui/Spinner'
import { styled, theme } from '@src/stitches.config'
import * as React from 'react'
const StyledButton = styled('button', {
fontFamily: '$inter',
fontWeight: '$700',
borderRadius: '$4',
import 'navigator.locks'
export async function getSession(ctx) {
if (typeof window === 'undefined') {
const session = await _fetchData("session", ctx)
return session
}
return navigator.locks.request('NEXT_AUTH:GET_SESSION', async () => {
const session = await _fetchData("session", ctx)
if (ctx?.triggerEvent ?? true) {
@mtt87
mtt87 / hubspot-tracking.md
Last active September 7, 2021 10:24
Hubspot track users after they signup with social login

We use social login (Google, GitHub and Microsoft as Identity Providers) and we wanna understand users that signup where they came from. The flow looks like this

  1. User lands on the website for example from a campaign (utm params in the url)
  2. User accepts the hubspot tracking banner
  3. User clicks on the signup button
  4. User is redirected to our "developer portal" where we trigger a social login with their selected provider. We have the hubspot tracking code running also on our developer portal.
  5. User finishes the signup and lands on our internal console dashboard

Problem

We are pushing a new contact to Hubspot on step 5 but at that point we lose all the information about how the user landed in first place on our website, if it was direct traffic or ads campaign etc because we are creating the contact from our backend calling the Hubspot API.

@mtt87
mtt87 / how_does_it_work.md
Created May 25, 2021 23:35
Next.js bundling / library investigation

Understanding next.js bundling and 3rd party libraries

Simple next.js app with no styles, no images, just a simple <h1>hello world</h1>

Page                             Size     First Load JS
┌ ○ /                            268 B          63.2 kB
├   /_app                        0 B            62.9 kB
└ ○ /404                         3.06 kB          66 kB
+ First Load JS shared by all    62.9 kB
  ├ chunks/framework.56721e.js   42 kB
/* eslint react/jsx-props-no-spreading:0 */
import React, { ReactNode } from 'react';
import { ViewProps } from 'react-native';
import {
SpaceProps,
ColorProps,
LayoutProps,
FlexProps,
FlexDirectionProps,
AlignItemsProps,
@mtt87
mtt87 / Button.tsx
Created October 16, 2019 12:51
React Native Button using styled-system
import styled from '@emotion/native';
import {useTheme} from 'emotion-theming';
import theme from '../theme';
import {space, layout, typography, color, variant} from 'styled-system';
type Variants = keyof typeof theme.buttons;
const BtnWrapper = styled.View`
${space}
${layout}
@mtt87
mtt87 / README.md
Last active May 19, 2019 09:40
Now (v2) with Gatsby + lambda node functions

Running now dev works fine for the Gatsby website and I can see it correctly at http://localhost:3000. But as soon as I browse to /api/locations it doesn't work anymore:

> GET /api/locations
> Building @now/node:api/locations/index.js
downloading user files...
installing dependencies for user's code...
installing to /var/folders/4y/mlqsnhbx4yx7kwfcg8s3b9880000gn/T/co.zeit.now/dev/workPaths/7fvnfnob/api/locations
running user script...
running "npm run now-build"