Skip to content

Instantly share code, notes, and snippets.

View martinratinaud's full-sized avatar
😀

Martin Ratinaud. Web Solutions Creator. martinratinaud

😀
View GitHub Profile
@martinratinaud
martinratinaud / countries-translation.js
Created March 9, 2023 04:52
Get translated country names in javascript
const frRegionNames = new Intl.DisplayNames(["fr"], { type: 'region' });
frRegionNames.of("US") // 👉 'États-Unis'
const enRegionNames = new Intl.DisplayNames(["en"], { type: 'region' })
enRegionNames.of("US") // 👉 'United States'
const esRegionNames = new Intl.DisplayNames(["es"], { type: 'region' })
esRegionNames.of("US") // 👉 'Estados Unidos
@martinratinaud
martinratinaud / filter-boolean.js
Created April 3, 2023 07:45
One Liner to filter empty values from an array
// One-Liner to filter all empty values from an array
const words = ["Follow", undefined, "@martinratinaud", null, '', "now!"]
const sentence = words.filter(Boolean)
console.log(sentence.join(" ")) // Follow @martinratinaud now!
@martinratinaud
martinratinaud / Scraper.ts
Last active April 7, 2023 10:49
Check backlink existence and rel after buying them
import axios, { AxiosRequestConfig } from 'axios';
import { JSDOM } from 'jsdom';
export default class Scraper {
public JSDOM = JSDOM;
constructor() {}
async getUrl(url: string, axiosConfig?: AxiosRequestConfig) {
const { headers, ...options } = axiosConfig || {};
@martinratinaud
martinratinaud / .bashrc
Created April 7, 2023 12:29
Compress mp4 on mac using ffmpeg
video_compress() {
filename_without_extension="${input_file%.*}"
extension="${input_file##*.}"
output_file="${filename_without_extension}-compressed.${extension}"
ffmpeg -i "$input_file" -vcodec libx264 -crf 23 -acodec aac -strict -2 -movflags faststart "$output_file"
}
@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;
@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 / 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 / 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 / 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 / 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,