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 / remove-docker-logs.sh
Created June 29, 2021 11:33
Remove all docker logs at once
sudo sh -c 'truncate -s 0 $(docker system info | grep "Docker Root Dir" | cut -d ":" -f2 | cut -d " " -f2-)/containers/*/*-json.log';
@martinratinaud
martinratinaud / Footer.tsx
Last active June 7, 2021 07:52
How to show your app version in a nextjs application
@martinratinaud
martinratinaud / typescriptreact.json
Last active May 11, 2021 06:39
VSCode Snippet to Create a typescript react functional component
{
"snippet-rf": {
"prefix": "rf",
"body": [
"import React from 'react';",
"import s from './${TM_FILENAME_BASE}.module.css'",
"",
"",
"interface ${TM_FILENAME_BASE}Props {",
" // TODO",
@martinratinaud
martinratinaud / filter-duplicates.ts
Last active May 10, 2021 10:48
Filter duplicates in array of objects - one line
const uniqueBy = (items: any[]) => (key: string) =>
[...new Map(items.map(item => [item[key], item])).values()]
// OR
const unique = [...new Map(items.map(item => [item[key], item])).values()];
@martinratinaud
martinratinaud / replaceNotTextCharacters.ts
Last active April 28, 2021 10:54
Keep only text and numeric characters in any alphabet
// \p{L} for any text character
// \d for any digit
// /u for unicode
const replaced = url.replace(/[^\p{L}\d]/gimu, '')
@martinratinaud
martinratinaud / get-current-timezone.ts
Last active April 22, 2021 06:43
Get current user timezone and timezone delay
const timezone: string = Intl.DateTimeFormat().resolvedOptions().timeZone; // Gives "Indian/Mauritius"
const timezoneDelayInMinutes: number = new Date().getTimezoneOffset(); // -240 because of GMT+4
@martinratinaud
martinratinaud / one-liner-array-shuffle.ts
Last active March 31, 2021 09:44
One liners javascript typesccript
// shuffle an array
const shuffle = (array: any[]) => array.sort(() => 0.5 - Math.random());
@martinratinaud
martinratinaud / login.js
Created October 21, 2020 15:06
puppeteer - login in with Google
const puppeteer = require('puppeteer');
const assert = require('assert');
const BASEURL="https://www.something.com"
(async () => {
const browser = await puppeteer.launch({
headless: process.env.CI === 'true',
slowMo: 20,
devtools: process.env.CI !== 'true',
args: [
@martinratinaud
martinratinaud / typescript-conditional-types.ts
Last active February 27, 2020 06:54
Typescript Conditional Types - The simple example
// full article https://medium.com/@martinratinaud/typescript-conditional-types-the-simple-example-8c971c04b6bc
// playground https://www.typescriptlang.org/play/#code/PTAEDEFcBttBDATgFwJYGNoFNQHsB2oAFssgA4DOAXCALZYAmqktAdOrrcAAK1Jr5E8AfEgNgyAJ5ksFdIlRlkAWg74maAvGjKpMirqJZlFVLTLZlWAB7xzlgBzoAnAHYAjOgAMAFgBGAGx+6ABQIXo4AJIAKtI4ALygAOTQkgroFEmgAD7JFBaoyEkA3OFxoJEUADJpGBQA8ogAygXIADzRAHygidGgNshY6hTJqemZoAD8oAAKiJyoFFhtAERjdSvdVKAr+dCFK6UhahTIoABmkPjoPaAAFBHbMXEAlE-VtRmNLfvtzzLdeLdADeIVA4NAqHO9wiPXiiRSn0yL1AoIh6NAiCwyEgiEIcwWS1YWIouGgADcsHdEeMki9SuiAL5giFYnF4vKtEohZlAA
type IType = 'lyrics' | 'split';
type IsLyricsOrSplit<T> = T extends 'lyrics' ? Promise<"lyrics"> : "split";
const func = (type: IType): IsLyricsOrSplit<IType> => {
if (type === 'lyrics') {
return Promise.resolve('lyrics');
}
@martinratinaud
martinratinaud / google-etes-catching-design-remover.js.js
Last active January 17, 2020 10:51
Tampermonkey script to remove new 2020 design from Google with big opaque links
// ==UserScript==
// @name Google eyes-catching-design remover
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Will put a lower opacity on the url because since last update, it is too eye-catching for me
// @author Martin Ratinaud <[email protected]>
// @include /^https?://.*\.google\..*/*/
// @grant none
// ==/UserScript==