Skip to content

Instantly share code, notes, and snippets.

View celian-rib's full-sized avatar
🛰️
probably parsing something with no garbage collector

Célian Riboulet celian-rib

🛰️
probably parsing something with no garbage collector
View GitHub Profile
@celian-rib
celian-rib / useEffectForegroundOnly.js
Created July 25, 2022 17:45
React Native useEffect that takes effect only when app is in foreground
import { useEffect, useRef } from 'react';
import { AppState } from 'react-native';
/**
* Accepts a function that contains imperative, possibly effectful code.
* Same as useEffect but has not effect when app is in background
*
* If the depencies changes while being in background, the effect will be executed after the app is in foreground again
*
* @param {*} effect Imperative function that can return a cleanup function
@celian-rib
celian-rib / Makefile
Created November 5, 2021 21:57
Generic makefile
# Name of the main target (= executable name)
TARGET = target_name
# Compiler command to use
CC = gcc
# Flags to add to the compiler command
CFLAGS = --std=c11 -g -Wall -Wextra -Wunused -pedantic -D_XOPEN_SOURCE=700
# Ncurse specific flag
# LDFLAGS=-lncurses # UNCOMMENT
@celian-rib
celian-rib / pre-commit
Last active November 3, 2021 18:30
Clean makefiles in sub-folders on pre-commit
cd $(git rev-parse --show-toplevel)
echo "Cleaning all make files"
make clean 2> /dev/null
for d in */ ; do
cd $d
make clean 2> /dev/null && echo "Cleaning $d"
cd ..
@celian-rib
celian-rib / HeaderGenerator.sh
Last active September 15, 2021 07:59
Add a custom text header to you code files
headerFile="header.txt"
fileExt=".java"
red=`tput setaf 1`
green=`tput setaf 2`
cyan=`tput setaf 6`
yellow=`tput setaf 3`
reset=`tput sgr0`
function main () {
@celian-rib
celian-rib / ScannerUtils.java
Created May 19, 2021 14:46
Collection of static methods meant to help reading user's inputs from the terminal in java
package yourpackage;
import java.util.Scanner;
public class ScannerUtils {
/**
* Wait for the user to enter any string in the terminal
*
* @param prefix text prefix to display on the same line as the user input
@celian-rib
celian-rib / ReactNative_FC_Template.ts
Last active November 15, 2021 21:43
React Native functional component template in typescript
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
interface Props {
someProp: string;
}
const ComponentName = (props: Props): JSX.Element => {
const {
someProp
@celian-rib
celian-rib / ContextProviderTemplate.ts
Last active July 20, 2023 04:11
React Context Provider template with TypeScript
import React, {
createContext, useContext
} from 'react';
interface MyContextProps {
attribute: unknown,
}
const MyContext = createContext<MyContextProps>({} as MyContextProps);
@celian-rib
celian-rib / useOnMiddleOfScreen.ts
Last active May 22, 2021 21:21
React hook to know if an element is in the middle of the window.
import { useState, useEffect } from 'react';
/**
* Check is an HTML element is in the middle of the window
* @param ref The HTML element to check
* @param range The range in which that define the middle zone
* @returns true if the provided ref is in the middle of the window
*/
export default const useOnMiddleOfScreen = (ref: React.RefObject<HTMLDivElement>, range: number): boolean => {
@celian-rib
celian-rib / typeOfInterface.ts
Last active April 25, 2021 16:42
Check if variable is of type Interface in TypeScript
interface myInterface {
myValue: any,
}
// The variable for which we will need to check the type
let myVariable: any | myInterface;
// ...
@celian-rib
celian-rib / useScrollBlock.ts
Last active May 24, 2024 08:54 — forked from reecelucas/useScrollBlock.js
React hook to enable/disable page scroll (Typescript version)
import { useRef } from 'react';
const safeDocument: Document = document;
/**
* Usage:
* const [blockScroll, allowScroll] = useScrollBlock();
*/
export const useScrollBlock = (): [() => void, () => void] => {
const scrollBlocked = useRef(false);