Skip to content

Instantly share code, notes, and snippets.

View martinratinaud's full-sized avatar
😀

Martin Ratinaud. Freelancer. martinratinaud

😀
View GitHub Profile
@martinratinaud
martinratinaud / .gitconfig
Last active August 29, 2015 14:17
git alias to display changed file on branch and see if they pass your linter
...
[alias]
changed = "!BASE_REV=`git merge-base master $(git rev-parse --abbrev-ref HEAD)`;git diff --diff-filter=ACMR --name-only $BASE_REV HEAD"
check-lint = "!for file in `git changed | grep -e '\\.js$'`;do node_modules/.bin/eslint --config .eslintrc $file;done;"
ch = "!git changed"
cl = "!git check-lint"
...
@martinratinaud
martinratinaud / node_i
Created November 13, 2018 12:52
`npm install` or `yarn` depending on which lock file is present
node_i() {
[ -f package-lock.json ] && NPM_I=true;
[ -f yarn.lock ] && YARN=true;
if [[ $NPM_I = true && $YARN = true ]]; then
echo -ne "\033[0;31myou have a package-lock.json and a yarn.lock, you should pick up only one!\033[0m"
echo ""
else
if [ $NPM_I ]; then
npm i
fi
@martinratinaud
martinratinaud / index.html
Created November 22, 2018 12:00
Improve first contentful paint in react
<div id="root">
<div class="full-page-loader">
<img width="200" src="/logo/aiptrade-vertical-color-color.png" alt="AIP.Trade logo" />
</div>
</div>
@martinratinaud
martinratinaud / FullPageLayout.tsx
Last active March 7, 2022 20:48
typescript Dot Notation styled-components
import * as React from 'react';
import styled from 'styled-components';
const FullPageLayout = styled<any>(styled.div``)`
display: flex;
flex-direction: column;
`;
interface HeaderProps {
fixed?: boolean;
printf -- "\033[32m ============================================= \033[0m\n";
printf -- "\033[32m Good morning dear \033[0m, Ready to rock?\n";
printf -- "\033[32m ============================================= \033[0m\n";
printf -- "Grab a coffee while I check if your repos are all clean\n"
STATUS=$(mgitstatus -e --no-stashes --no-upstream .. 1)
if [ -z "$STATUS" ]
then
@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 <martinratinaud@gmail.com>
// @include /^https?://.*\.google\..*/*/
// @grant none
// ==/UserScript==
@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 / 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 / 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 / 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