Skip to content

Instantly share code, notes, and snippets.

View mtt87's full-sized avatar
πŸ”

Mattia mtt87

πŸ”
View GitHub Profile
@mtt87
mtt87 / PromiseRecursion.js
Created December 19, 2016 12:03
Promise recursion
function fetchPages(resultsArray, page, end) {
return new Promise((resolve, reject) => {
fetch(`https://my-api.com/?page=${page}`)
.then((res) => {
// res.json
// {
// data: [1,2,3],
// nextPage: 1,
// previousPage: 0,
// }
import React from 'react';
import BigCalendar from 'react-big-calendar';
import SingleEvent from './SingleEvent';
// THIS WORKS
const Calendar = ({ refreshData }) =>
...
<BigCalendar
components={{
eventWrapper: SingleEvent,
@mtt87
mtt87 / Component_1.js
Created March 5, 2019 01:16
Fetch dynamically a component and render it at runtime on React Native
// This DOES NOT work (require is undefined)
import React from 'react';
import { View, Text } from 'react-native';
const Component = () => (
<View>
<Text>Hello world</Text>
</View>
);
@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"
@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}
/* 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 / 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
@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.

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) {
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',