Skip to content

Instantly share code, notes, and snippets.

View scorsi's full-sized avatar
😬
What if... hugh.. whatever

Sylvain Corsini scorsi

😬
What if... hugh.. whatever
  • Asobo Studio
  • France, Lille
  • 07:12 (UTC +02:00)
View GitHub Profile
defmodule Torch.Templates do
@moduledoc """
Module allowing to automatically manage templates depending of the given mix task
"""
@template_path "priv/templates"
def inject_templates(mix_task, options) do
out_directory = Keyword.get(options, :out_directory, "#{@template_path}/#{mix_task}")
@scorsi
scorsi / useWindowDimensions.tsx
Last active April 30, 2020 14:47
Get window width and match
import {useEffect, useState} from 'react';
const getWindowDimensions = () => {
const {innerWidth: width, innerHeight: height} = window;
return {
width,
height
};
};
@scorsi
scorsi / fetch.js
Created February 27, 2020 15:18
A Fetch hook with super-powers, lightweight but very performant
// eslint-disable-next-line import/no-mutable-exports,prefer-const
export let baseUrl = process.env.REACT_APP_API_DOMAIN;
export const constructUrl = (path, queryParams = null) => {
const _url = new URL(baseUrl);
_url.pathname = path;
if (queryParams) _url.search = new URLSearchParams(queryParams).toString();
return _url.toString();
};
@scorsi
scorsi / useIsMounted.js
Created February 27, 2020 15:07
A hook useful to know if the current component is still mounted
import { useEffect, useRef } from 'react';
export default () => {
const isMounted = useRef(null);
useEffect(() => {
isMounted.current = true;
return () => { isMounted.current = false; };
}, []);
@scorsi
scorsi / useLocalStorage.js
Created February 27, 2020 15:07
A hook useful to get/set data from/to localstorage
import { useState } from 'react';
export default (key, initialValue) => {
const [storedValue, setStoredValue] = useState(() => {
try {
const item = window.localStorage.getItem(key);
return item ? JSON.parse(item) : initialValue;
} catch (error) {
console.log(error);
return initialValue;
@scorsi
scorsi / useCancellablePromise.js
Last active February 27, 2020 15:06
Automaticaly cancel Promise when component did unmount compatible with AbortController for fetch
import { useEffect, useRef } from 'react';
export function PromiseCanceledError() {
this.name = 'PromiseCanceledError';
}
const makeCancelable = (promise, abortController) => {
let isCanceled = false;
const wrappedPromise = new Promise((resolve, reject) => {
@scorsi
scorsi / Router.jsx
Created February 27, 2020 15:03
My React Router using hooks
import React, {
createContext,
useEffect,
useState,
useContext,
useMemo,
useCallback
} from "react";
import history from "browser-history";
import pathToRegexp from "path-to-regexp";
extends KinematicBody2D
const WALK_SPEED = 125
const RUN_SPEED = 250
const GRAVITY_FORCE = 10
const JUMP_FORCE = 280
const AIR_CONTROL = 200
var velocity = Vector2.ZERO
@scorsi
scorsi / remove-gitignore-files.sh
Created May 29, 2019 16:18
Remove files from a git repository which are present in .gitignore
git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
## STOP all containers
echo "Stoping all running containers"
docker ps -q | xargs --no-run-if-empty docker stop 2> /dev/null
## RM all containers
echo "Removing all containers"
docker ps -q -a --no-trunc --filter "status=exited" | xargs --no-run-if-empty docker rm 2> /dev/null
## RM all volumes
echo "Removing all volumes"
docker volume ls -q -f "dangling=true" | xargs --no-run-if-empty docker volume rm 2> /dev/null
## RM all networks