Skip to content

Instantly share code, notes, and snippets.

View ylastapis's full-sized avatar

yann lastapis ylastapis

  • Toulouse France
View GitHub Profile
@ylastapis
ylastapis / .eslintrc.json
Last active January 3, 2022 13:41
React / TypeScript / Prettier / StyleLint Setup files
{
"extends": ["react-app", "eslint:recommended", "plugin:react/recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"plugins": ["react", "@typescript-eslint", "react-hooks", "import"],
"env": {
"browser": true,
"jasmine": true,
"jest": true
},
"rules": {
@ylastapis
ylastapis / map.selectors.ts
Created November 19, 2019 14:29
Change default memoize function of createSelector in reselect
import { createSelector, createSelectorCreator, defaultMemoize } from 'reselect';
// only care about height, lat & lng
export const FlightPlanSelector = createSelectorCreator(
defaultMemoize as any,
(a: FlightPlanPoint, b: FlightPlanPoint) => a.height === b.height && a.lat === b.lat && a.lng === b.lng
);
// use the new defined selector FlightPlanSelector
export const selectNotamTrajectoryPoints = FlightPlanSelector(
selectMapValueFP('flightPlan'),
(flightPlan) => flightPlan.map(fp => ({
@ylastapis
ylastapis / ConfirmationDialog.tsx
Created November 18, 2019 15:30
Add a Dialog confirmation to any action in any component in React, using Hooks & Context
import React from 'react';
import { Button } from '../../../components/UI/new/Button';
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
import { ButtonsContainer } from '../../../components/UI/new/ButtonsContainer';
import { FormattedMessage } from 'react-intl';
export interface ConfirmationOptions {
title: string | React.ReactNode;
confirmLabel: string | React.ReactNode;
description: string | React.ReactNode;
@ylastapis
ylastapis / AvoidAnonymousFunctions.tsx
Last active April 19, 2019 07:33
React / Redux Best practices
// Avoid anonymous functions
// Don't do this!
function Component(props) {
return <AnotherComponent onChange={() => props.callback(props.id)} />
}
// Do this instead :)
function Component(props) {
const handleChange = useCallback(() => props.callback(props.id), [props.id]);
@ylastapis
ylastapis / addons.js
Created November 16, 2018 13:36
CRA 2.1 + Storybook + typescript + jest
// ./.storybook/addons.js
import '@storybook/addon-actions/register';
import '@storybook/addon-links/register';
import '@storybook/addon-knobs/register';
import 'storybook-addon-intl/register';
@ylastapis
ylastapis / Any.ts
Created October 12, 2018 08:06
react-intl + typescript + storybook
// components/Any.ts
import * as React from 'react';
import { FormattedMessage, InjectedIntlProps } from 'react-intl';
export interface AnyMapStateToProps {
// your state actions here
}
export interface AnyMapDispatchToProps {
// your dispatch actions here
@ylastapis
ylastapis / ProductCategory.orm.xml
Last active September 1, 2016 07:51
Add a Custom Entity with translations to Sylius
// src/AppBundle/Resources/config/doctrine/ProductCategory.orm.xml
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass name="AppBundle\Entity\ProductCategory" table="app_product_category" repository-class="AppBundle\Entity\Repository\ProductCategoryRepository">
<id name="id" column="id" type="integer">
@ylastapis
ylastapis / LocaleSubscriber.php
Created July 29, 2016 12:49
Locale Subscriber to force Locale over API calls on Sylius
<?php
namespace AppBundle\EventSubscriber;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Core\Locale\LocaleStorageInterface;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use Sylius\Component\Locale\Provider\LocaleProvider;
use Sylius\Component\Locale\Provider\LocaleProviderInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ylastapis
ylastapis / AppBundle.Document.StaticContent.xml
Created June 29, 2016 15:55
Extend Sylius StaticContent model
<!--file: src/AppBundle/Resources/rdf-mappings/AppBundle.Document.StaticContent.xml-->
<type
xmlns:schema="http://schema.org/"
typeof="schema:WebPage"
>
<children>
<property property="schema:headline" identifier="title" tag-name="h1"/>
<property property="schema:text" identifier="body" />
<property property="schema:text" identifier="group" />
</children>
@ylastapis
ylastapis / Configuration.php
Created May 23, 2016 09:23
AWS 3 with Symfony2 and Gaufrette
<?php
namespace AppBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()