Skip to content

Instantly share code, notes, and snippets.

View tyx's full-sized avatar

Timothée Barray tyx

View GitHub Profile
@merelinguist
merelinguist / useLoaderData.ts
Created February 1, 2022 10:38
Transforms any Date objects from your Remix loaders into strings for a more accurate representation of Remix's deserialisation
import { useLoaderData as useRemixLoaderData } from "remix";
type Nullable<Type> = Type | undefined | null;
type Deserialized<Data> = {
[Key in keyof Data]: Data[Key] extends Nullable<{ [key: string]: unknown }>
? Deserialized<Data[Key]>
: Data[Key] extends Date
? string
: Data[Key];
@f2r
f2r / README.md
Last active October 1, 2020 18:01

Exercice de codage PHP

(date de fin du défit : 24 juin 2020 à minuit)

Vous disposez de 4 fichiers CSV contenant chacuns 2 colonnes : un index (unique et en ordre croissant) et une valeur.

Vous devez rassembler ces données dans un fichier CSV avec 5 colonnes :

  • index
  • valeur fichier data1
  • valeur fichier data2
@MastaAaron
MastaAaron / category-schema.js
Last active May 20, 2023 09:50
Sanity CMS: Infinitely-nestable Categories
export default {
name: `category`,
title: `Category`,
type: `document`,
fields: [
{
name: `name`,
title: `Category Name`,
type: `string`,
validation: Rule => Rule.required()
@jon-acker
jon-acker / library.md
Created September 15, 2019 15:33
Library Lending System BDD/TDD Kata

Library Lending System

Objective: collaboratively come up with use-case examples and write executable specifications (Gherkin scenarios) for system that allows library members to borrow and return book, as well as charge the correct overdue fines.

Use the scenarios to drive the code to create a software model of the library lending process (the end product is a bunch of classes that can be instantiated and used to run business)

Identify the boundaries of the system (where infrastructure would be connected .e.g. apis or database) and use interfaces at these points. Provide fake implementations for the infrastructure in order to run the scenarios.

Identify the ubiquitous language of the library lending and fine charging domain and use the same language to write the scenarios in.

@Billz95
Billz95 / .php_cs.dist
Last active January 15, 2024 02:58
A Customised fixer for PHP-CS-Fixer to use `prettier`'s php plugin to pre-process the code before getting analysed by other fixers. This would enable `php-cs-fixer` to take advantage of `prettier`'s ability of managing long line.
<?php
require_once __DIR__.'/relative/path/to/PrettierPHPFixer/File';
return PhpCsFixer\Config::create()
->registerCustomFixers([
(new PrettierPHPFixer()),
])
->setRules([
'Prettier/php' => true,
@lyrixx
lyrixx / BrokerFactory.php
Last active July 1, 2019 15:21
PHPStan extension to extract property type hint from constructor argument
<?php
use PHPStan\Broker\Broker;
use PHPStan\Broker\BrokerFactory as PhpstanBrokerFactory;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\Php\PhpPropertyReflection;
use PHPStan\Reflection\PropertiesClassReflectionExtension;
use PHPStan\Reflection\PropertyReflection;
use PHPStan\Type\ObjectType;
@soyuka
soyuka / IriConverter.php
Created September 6, 2018 10:19
Override IriConverter and allow an ApiResource to not have any item route associated with it.
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
@mathiasverraes
mathiasverraes / rollyourown.php
Created May 30, 2018 14:17
We don't need no DIC libs / we don't need no deps control
<?php
// Context: I'm trying to argue that DI (and DIC) are great, and DIC libs suck.
// Happy to be proven wrong!
final class Router {
private $dependencies;
public function __construct (Dependencies $dependencies) {
$this->dependencies = $dependencies;
// You might say that this is Service Locator, but it's not. This router is toplevel,
// and toplevel must have access to dependencies. After that it can all just bubble nicely using proper DI.
@developit
developit / *state-machine-component.md
Last active February 6, 2021 00:44
265b lib for building pure functional state machine components. https://github.com/developit/state-machine-component

state-machine-component

A tiny (265 byte) utility to create state machine components using two pure functions.

🔥 JSFiddle Demo

Usage

The API is a single function that accepts 2 pure functions as arguments:

<?php
namespace Infrastructure\Composer;
use Composer\Installer\InstallationManager;
use Composer\Package\CompletePackage;
use Composer\Repository\InstalledFilesystemRepository;
use Composer\Script\Event;
use Composer\Util\Filesystem as ComposerFilesystem;
use Symfony\Component\Filesystem\Filesystem;