Skip to content

Instantly share code, notes, and snippets.

View webflo-dev's full-sized avatar

Florent webflo-dev

View GitHub Profile
@webflo-dev
webflo-dev / example1.tsx
Created June 21, 2021 07:48
Conditionnal Props in React/TypeScript
type DrawerProps = { fullName: string } & (
| { shape: 'circle'; radius: number }
| { shape: 'square'; width: number }
| { shape: 'rectangle'; width: number; height: number }
);
@webflo-dev
webflo-dev / modal.jsx
Created April 14, 2021 09:52 — forked from viclafouch/modal.jsx
An implementation of a Modal Component with React Hooks ! See https://react-modal.viclafouch.vercel.app
import React, { useEffect, useImperativeHandle, useState, forwardRef, useCallback } from 'react'
import { createPortal } from 'react-dom'
import './styles.css'
const modalElement = document.getElementById('modal-root')
export function Modal({ children, fade = false, defaultOpened = false }, ref) {
const [isOpen, setIsOpen] = useState(defaultOpened)
const close = useCallback(() => setIsOpen(false), [])
@webflo-dev
webflo-dev / enum.go
Created December 22, 2020 10:59 — forked from lummie/enum.go
Golang Enum pattern that can be serialized to json
package enum_example
import (
"bytes"
"encoding/json"
)
// TaskState represents the state of task, moving through Created, Running then Finished or Errorred
type TaskState int
@webflo-dev
webflo-dev / rclone-cron.sh
Created October 4, 2020 12:14 — forked from jaredmales/rclone-cron.sh
An rclone backup script for cron
#!/bin/bash
##############################################################################
# An rclone backup script by Jared Males ([email protected])
#
# Copyright (C) 2018 Jared Males <[email protected]>
#
# This script is licensed under the terms of the MIT license.
# https://opensource.org/licenses/MIT
#
@webflo-dev
webflo-dev / sed cheatsheet
Created August 28, 2020 13:08 — forked from un33k/sed cheatsheet
magic of sed -- find and replace "text" in a string or a file
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@webflo-dev
webflo-dev / Dockerfile
Created August 4, 2020 14:51
ubuntu image with non-root user
FROM ubuntu:latest
RUN apt -y update && \
apt -y full-upgrade && \
apt -y autoremove && \
apt -y install sudo zsh git curl
RUN useradd -U -m john && \
usermod -aG sudo -s /bin/zsh john && \
echo "john ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/john && \
#!/bin/bash
CHECK_SYMBOL='\u2713'
X_SYMBOL='\u2A2F'
#
# Run the command passed as 1st argument and shows the spinner until this is done
#
# @param String $1 the command to run
# @param String $2 the title to show next the spinner
# @param var $3 the variable containing the return code
@webflo-dev
webflo-dev / read_ini_file.sh
Last active June 29, 2020 18:08
read ini file using shell script
# List all [sections] of a .INI file
sed -n 's/^[ \t]*\[\(.*\)\].*/\1/p' $ini_file
# Read KEY from [SECTION]
sed -n '/^[ \t]*\[SECTION\]/,/\[/s/^[ \t]*KEY[ \t]*=[ \t]*//p'
# Read all values from SECTION in a clean KEY=VALUE form
sed -n '/^[ \t]*\[SECTION\]/,/\[/s/^[ \t]*\([^#; \t][^ \t=]*\).*=[ \t]*\(.*\)/\1=\2/p'
@webflo-dev
webflo-dev / background.js
Created September 10, 2018 08:45 — forked from davlgd/background.js
Bad Search Engine Blocker - Projet final
chrome.webRequest.onBeforeRequest.addListener(function (request) {
const askedURL = new URL(request.url);
const keywords = askedURL.searchParams.get("q");
if (/bing.|google.|yahoo./.test(askedURL.hostname))
{
const destinationUrl = (keywords) ? "https://www.framabee.org?q=" + keywords : "https://www.framabee.org";
return { redirectUrl: destinationUrl };
}
},