Skip to content

Instantly share code, notes, and snippets.

@tasiot
tasiot / ConstraintsFromExtension.php
Last active May 28, 2023 19:32
Apply related entity constraints in a symfony form unmapped field
<?php
// App/Form/Extension/ConstraintsFromExtension.php
declare(strict_types=1);
namespace App\Form\Extension;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\FormBuilderInterface;
@tasiot
tasiot / SecurityHelper.php
Created April 25, 2023 15:46
Symfony user roles
<?php
declare(strict_types=1);
namespace App\Service;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
use Symfony\Component\Security\Core\User\UserInterface;
class SecurityHelper
@tasiot
tasiot / bandwidth.sh
Created November 9, 2022 10:22
Show bandwidth for a month, using apache logs
# Count (in GB) the bandwidth using 10th field in apache log (content-length)
zcat /var/logs/apache2/*.gz | awk '$4~/Oct\/2022/ {SUM+=$10}END{print SUM/1024/1024/1024}'
@tasiot
tasiot / listdirs.md
Created July 18, 2022 16:56
List all folders as tree
@tasiot
tasiot / mysql-docker.sh
Created December 7, 2021 11:08 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@tasiot
tasiot / AppExtension.php
Last active January 5, 2024 16:56
Twig pluralize filter
<?php
namespace App\Twig;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class AppExtension extends AbstractExtension
{
public function getFilters(): array
@tasiot
tasiot / README.md
Last active April 28, 2021 23:14
Allows you to retrieve OVH Object Storage (swift) credentials for use with AWS S3 libraries

Explanations

The "Object Storage" offer from OVH is indicated as being S3 compatible, but the identifiers provided by OVH do not allow us to connect directly via the AWS S3 libraries.

You must therefore retrieve a token from OVH KeyStone, then use it to obtain the accesses that can be used by S3.

Usage

  1. Create a user account on OVH for Object Storage (with "Object Store" rights) and keep the username and password.
  2. Retrieve the projectName by clicking on "View Credentials" from the OVH Horizon interface.
  3. Enter these values in the PHP file and run it.
  4. It should return the values of UserID, AccessKey and Secret.
@tasiot
tasiot / gist:ff4533bd81864e95e85420bbde036ed2
Last active December 6, 2020 10:42
Process n mail from postfix mail queue with 5 seconds sleep for every mail (fix too many connection Orange)
for mailid in `mailq | awk '$1 ~ /^[0-9A-F]{11}$/ {print $1}' | head -n 50`; do postqueue -i $mailid; sleep 5; done;