Skip to content

Instantly share code, notes, and snippets.

View ninsuo's full-sized avatar
🐢

Alain Tiemblo ninsuo

🐢
View GitHub Profile
@ninsuo
ninsuo / CreatedAtType.php
Created January 12, 2023 13:15
Let the db manage created at / updated at fields with Doctrine
<?php
namespace Dot\SkeletonBundle\Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class CreatedAtType extends DateTimeImmutableUTCType
{
public const NAME = 'created_at';
@ninsuo
ninsuo / App\Doctrine\DBAL\Types\EnumType.php
Created January 3, 2023 10:08
A Doctrine enum type that supports PHP 8 native enums
<?php
namespace App\Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
class EnumType extends Type
{
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
@ninsuo
ninsuo / code.php
Created June 24, 2019 09:53
Cornichonize
<?php
class Cornicode
{
static public function cornichonize(string $text) {
// Reverse
$cypher = strrev($text);
// Rotate
@ninsuo
ninsuo / templatize.php
Created May 10, 2019 15:27
Takes each line in stdin, and wrap it with a template
<?php
if (!isset($argv[1])) {
die(sprintf('You forgot to give a template: %s "<prefix> %%s <suffix>"%s', $argv[0], "\n"));
}
$template = $argv[1];
$raw = file_get_contents('php://stdin');
$lines = explode(PHP_EOL, $raw);
@ninsuo
ninsuo / degrade.php
Created March 6, 2019 09:58
degrade.php - the most ugly code i ever made in life
<?php
// ------------------------------------------
// DEGRADE ( GD )
// ------------------------------------------
// ---------------------------------------------
// Allowed GET arguments:
// a -> applies transparency to background color
// c -> colors (use '-' for color separator)
<?php
/**
* Cette classe permet d'écrire un document de type plain/text
* formatté en monospace.
*
* Cette classe supporte :
* - les lignes
* - l'alignement
* - les sauts de ligne
@ninsuo
ninsuo / certbot-auto-renew.sh
Last active June 15, 2017 07:51
auto renewing cerificates generated from lets-encrypt
#!/dgr/bin/busybox sh
# copied from https://github.com/n0rad/rkt-images/blob/master/aci/arch/aci-arch-nginx-certbot/templates/start.tmpl.sh
set -e
. /dgr/bin/functions.sh
isLevelEnabled "debug" && set -x
## Create certif
# certbot certonly --email email@example.com --webroot -w /var/lib/letsencrypt/ -d domain.tld,sub.domain.tld
@ninsuo
ninsuo / tmux_cheatsheet.markdown
Created December 15, 2016 14:47 — forked from henrik/tmux_cheatsheet.markdown
tmux cheatsheet

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@ninsuo
ninsuo / xliff-to-yaml.php
Last active January 18, 2019 07:15
Takes a Symfony xlf file and converts it to YAML
<?php
$content = file_get_contents('messages.en.xlf');
/*
Converts crazy xliffs files into readable yaml:
<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
@ninsuo
ninsuo / tidypics.php
Last active February 23, 2016 07:53
Tidy up pictures from a camera (generated path format: Y-m-d/H:i:s.ext)
<?php
# Run me inside a directory full of pictures
# Create an alias for easier use!
date_default_timezone_set('Europe/Paris');
$path = $_SERVER['PWD'];
$glob = glob("/{$path}/*");