Skip to content

Instantly share code, notes, and snippets.

View martinratinaud's full-sized avatar
😀

Martin Ratinaud. Freelancer. martinratinaud

😀
View GitHub Profile
import React from 'react';
import classNames from 'classnames';
import usePwa from '../hooks/usePwa';
import { useTranslation } from 'modules/i18n'; // Make sure to import useTranslation
type InstallPwaInstructionsProps = React.HTMLAttributes<HTMLDivElement> & {
// TODO
};
const InstallPwaInstructions: React.FC<InstallPwaInstructionsProps> = ({ className, ...props }) => {
@martinratinaud
martinratinaud / autocompletion.png
Last active September 12, 2023 06:18
usePublicRuntimeConfig hook for NextJs
autocompletion.png
@martinratinaud
martinratinaud / yup-schema.ts
Created August 25, 2023 04:55
Validate SIREN/SIRET with yup
// Luhn algorithm to validate the SIRET number
const luhnCheck = (num?: string) => {
if (!num) {
return false;
}
let arr = (num + '')
.split('')
.reverse()
.map((x) => parseInt(x));
let lastDigit = arr.splice(0, 1)[0];
@martinratinaud
martinratinaud / GeoDataProvider.tsx
Created June 15, 2023 11:00
GeoData provider and hook for React
import type { AppProps } from 'next/app';
import React from 'react';
import { useToggle } from 'react-use';
export const GeoDataContext = React.createContext({
geoData: undefined as GeoData | undefined,
});
export interface GeoData {
ip: string;
@martinratinaud
martinratinaud / page.tsx
Created June 9, 2023 11:58
Floating CTA using `react-use` `useIntersection`
import React from 'react';
import { useIntersection } from 'react-use';
const App = () => {
const intersectionRef = React.useRef(null);
const intersection = useIntersection(intersectionRef, {
root: null,
rootMargin: '0px',
threshold: 1,
@martinratinaud
martinratinaud / git_clone_gist.sh
Created May 26, 2023 06:06
Clone Gist repo to a well named repository
#!/bin/bash
git_clone_gist() {
# The URL of the gist is the first argument to the script
gist_url=$1
# Use the GitHub API to get the name of the first file in the gist
gist_id=$(basename $gist_url)
api_url="https://api.github.com/gists/$gist_id"
json=$(curl -s $api_url)
@martinratinaud
martinratinaud / followers-count-in-feed.gif
Last active May 26, 2023 05:58
Tampermonkey to add followers and following directly in the feed and not have to hover to see it
followers-count-in-feed.gif
@martinratinaud
martinratinaud / tampermonkey.js
Created May 10, 2023 10:36
Add nb followers and following directly in Twitter feed
// ==UserScript==
// @name Twitter better list
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add nb followers and following directly in feed
// @author Martin Ratinaud
// @match https://twitter.com/*
// @grant none
// ==/UserScript==
@martinratinaud
martinratinaud / Analytics.tsx
Last active May 10, 2023 14:15
Delay display of a component. Useful for scripts that male pageSpeed insights fail
const NEXT_PUBLIC_GTM_ID = process.env.NEXT_PUBLIC_GTM_ID;
const NEXT_PUBLIC_HOTJAR_ID = process.env.NEXT_PUBLIC_HOTJAR_ID;
import React from 'react';
import Script from 'next/script';
import Delayed from 'modules/Common/components/Delayed';
export default function HeadTag() {
return (
<>
{NEXT_PUBLIC_GTM_ID && (
@martinratinaud
martinratinaud / email.html
Last active April 16, 2023 17:11
Display subtitle in email clients
<html>
<head>
<style type="text/css">
.preheader {
display: none;
max-height: 0;
overflow: hidden;
visibility: hidden;
font-size: 0;
color: transparent;