Skip to content

Instantly share code, notes, and snippets.

View Nemo64's full-sized avatar

Marco Pfeiffer Nemo64

View GitHub Profile
@Nemo64
Nemo64 / sortable_select.tsx
Created July 14, 2023 17:29
sortable tags in ant.design Select mode="multiple"
function SortableSelect<ValueType extends Array<unknown>, OptionType>(
props: SelectProps<ValueType, OptionType>
) {
return (
<DndProvider backend={HTML5Backend}>
<Select<ValueType, OptionType>
{...props}
tagRender={({ label, ...tagProps }) => (
<DraggableTag
{...tagProps}
@Nemo64
Nemo64 / only-h264.sh
Created December 31, 2022 16:30
example ffmpeg.wasm-core configure scripts for different use cases
#!/bin/bash
# this results in a wasm file that is
# 5.2 mb (1.8 mb gzip)
set -euo pipefail
source $(dirname $0)/var.sh
FLAGS=(
"${FFMPEG_CONFIG_FLAGS_BASE[@]}"
@Nemo64
Nemo64 / AggressiveObjectNormalizer.php
Created September 26, 2022 14:49
This normalizer will normalize all properties of an object, regardless of visibility.
<?php
namespace App\Serializer;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
/**
* This normalizer will normalize all properties of an object, regardless of visibility.
* It will not use methods, just reflection access to properties.
*
@Nemo64
Nemo64 / api_platform.yaml
Created June 24, 2022 11:51
Good configuration examples for ApiPlatform Symfony project
api_platform:
# [...] leave the default configuration
defaults:
# only use pagination if explicitly requested
# otherwise, you'll just ignore it and have a broken application once you have more than 10 items
pagination_enabled: true
<?php
namespace App\Command;
use App\Entity\Order;
use App\Service\TickService;
use Doctrine\DBAL\LockMode;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console;
use Symfony\Component\Workflow\WorkflowInterface;
@Nemo64
Nemo64 / ElasticsearchProductProvider.php
Last active April 17, 2022 17:34
Elasticsearch API Platform -> FOS Elastica configuration
<?php
namespace App\Search;
use ApiPlatform\Core\DataProvider;
use FOS\ElasticaBundle\Index\IndexManager;
use Symfony\Component\Serializer\Serializer;
/**
* This class is based on API Platforms elasticsearch implemenation.
@Nemo64
Nemo64 / fastest.sh
Last active February 25, 2022 17:39
fastest shell script that uses symfony's simple-phpunit. description here: https://betterprogramming.pub/improve-phpunit-performance-by-parallelization-using-liuggio-fastest-ff0abc111078
#!/usr/bin/env sh
# run phpunit to trigger download in symfony
bin/phpunit --version
if [ $1 ]
then
find tests/ -name '*Test.php' \
| grep -i "$1" \
| vendor/bin/fastest -vv --no-errors-summary 'bin/phpunit {}'
@Nemo64
Nemo64 / EntityRestrictionInterface.php
Last active September 30, 2022 09:26
centralized symfony access control
<?php
namespace App\Security;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Security;
/**
* Allows access control to be defined within an entity.
@Nemo64
Nemo64 / SmoothAdc.h
Last active April 8, 2021 10:38
A class to take multiple samples of the ESP32 ADC
#pragma once
#include <driver/adc.h>
template<adc1_channel_t... PINS>
class SmoothAdc {
private:
const adc1_channel_t pins[sizeof...(PINS)] = {PINS...};
volatile uint32_t results[sizeof...(PINS)] = {};
uint16_t reads[sizeof...(PINS)][256] = {};
uint8_t position = 0;
@Nemo64
Nemo64 / doctrine_live_tempaltes.xml
Created March 29, 2021 11:42
Live templates for common doctrine fields
<template name="bool:default" value="/**&#10; * @var bool&#10; * @ORM\Column(type=&quot;boolean&quot;, options={&quot;default&quot;: $default$})&#10; */&#10;private bool $$$name$ = $default$;&#10;&#10;$END$&#10;&#10;public function is$method$(): bool&#10;{&#10; return $this-&gt;$name$;&#10;}&#10;&#10;public function set$method$(bool $$$name$): void&#10;{&#10; $this-&gt;$name$ = $$$name$;&#10;}" description="boolean column" toReformat="false" toShortenFQNames="true">
<variable name="name" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="default" expression="enum(&quot;false&quot;, &quot;true&quot;)" defaultValue="" alwaysStopAt="true" />
<variable name="method" expression="capitalize(name)" defaultValue="" alwaysStopAt="false" />
<context>
<option name="PHP Class Member" value="true" />
</context>
</template>
<template name="bool:nullable" value="/**&#10; * @var bool|null&#10; * @ORM\Column(type=&quot;boolean&quot;, nullable=true)&#10; */&#10;private ?bool $$$name$ = nul