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 / 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 / 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 / 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 / Footer.tsx
Last active June 7, 2021 07:52
How to show your app version in a nextjs application
@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 / extractDomainName.ts
Last active August 3, 2021 09:02
Extract domain name without subdomain from any url in javascript
const extractDomainName = (url:string) => {
const [extension, domain] = new URL(url).hostname.split('.').reverse();
return `${domain}.${extension}`;
}
@martinratinaud
martinratinaud / remove-unwanted-from-git.sh
Created August 9, 2021 04:03
Remove a password (or unwanted string) commited in github (or gitlab) from git history
#!/bin/bash
git filter-branch --tree-filter "find . -name 'ops/roles/ota/files/.env' -exec sed -i -e \
's/<thepasswordtoremove>/***REMOVED***/g' {} \;"
git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push --force --all
# If this commit was hosted on github, you will still be able to access the failing commit on the web
# which is not what you want
# This is because GitHub needs to run garbage collection and this will be done manually upon request
“Great people are those who make others feel that they, too, can become great.”
— Mark Twain
“Action is the universal language of success.”
— Dr. Steve Maraboli
@martinratinaud
martinratinaud / github-action.yml
Created April 1, 2022 10:12
Twitter optimal cron
name: optimal-post-on-twitter
on:
schedule:
- cron: '58 17 * * MON' # time adapted for NY timezone
- cron: '49 17 * * MON'
- cron: '32 13 * * TUE'
- cron: '58 17 * * TUE'
- cron: '49 21 * * TUE'
- cron: '32 13 * * WED'
@martinratinaud
martinratinaud / .gitconfig
Last active December 19, 2024 18:45
Awesome Git Configuration
[alias]
# shortcuts
c = commit
co = checkout
cp = cherry-pick
f = fetch
# enhancements
d = diff -- ':!package-lock.json' ':!yarn.lock' # Do not show lock files when diffing
ds = diff --staged -- ':!package-lock.json' ':!yarn.lock' # Do not show lock files when diffing staged files