Skip to content

Instantly share code, notes, and snippets.

View Glideh's full-sized avatar

Pierre de LESPINAY Glideh

  • Masao
  • France - Collégien (77)
View GitHub Profile
@Glideh
Glideh / AzureAuthenticator.php
Created September 12, 2022 06:28
Azure authentication guard for Symfony based on thenetworg/oauth2-azure
<?php
namespace App\Security;
use Firebase\JWT\JWT;
use Firebase\JWT\SignatureInvalidException;
use Symfony\Component\Cache\Adapter\AbstractAdapter;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
@Glideh
Glideh / DB backup, rotate & mirror.md
Created December 17, 2021 07:39
This is a suggestion of how to backup a DB (MySQL/MariaBD), rotate the backups and mirror them from another server

Backup managment

This is a suggestion of how to backup a DB (MySQL/MariaBD), rotate the backups and mirror them from another server

Backup

First we need to backup the database on a given frequency

  • Create a dedicated directory
@Glideh
Glideh / postman-prerequest-login.js
Last active November 9, 2023 08:49
Postman pre-request script to get a JWT if needed
/** Checks if the JWT is present and not expired
The token is expected to be found in `token` environment variable
*/
function isValidToken() {
const token = pm.environment.get("token");
if (!token) {
console.log("Token is missing");
return false;
}
// Payload is retrieved after JSON parsing the base64 decoded `atob()` 2nd part of the JWT `[1]`
@Glideh
Glideh / RolesType.php
Last active March 11, 2024 12:24
This is an example of how one could create a custom type for roles to add in a User form
<?php
namespace AdminBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
use Symfony\Component\Security\Core\Role\Role;
@Glideh
Glideh / queryBuilderGenerator.php
Last active July 7, 2016 09:45
Generates an array of key => alias pairs joins from dotted path ready for a Doctrine QueryBuilder
<?php
/**
* @param string|array $dottedParts
* @param string $parent
* @return array
*/
public function getJoinsFromDottedPath($dottedParts, $parent = 'entity')
{
if (!is_array($dottedParts)) {
// Assuming the $dottedParts is a string
@Glideh
Glideh / listSubviewsOfView.m
Last active May 25, 2022 02:36
Lists views recursively with indentation for subviews
- (void)listSubviewsOfView:(UIView *)view {
[self listSubviewsOfView:(UIView *)view withPrefix:@""];
}
- (void)listSubviewsOfView:(UIView *)view withPrefix:(NSString *)prefix {
NSArray *subviews = [view subviews];
for (UIView *subview in subviews) {
NSLog(@"%@ %@ (%d %d; %d %d)", prefix, subview.class
, (int)subview.frame.origin.x
, (int)subview.frame.origin.y
, (int)subview.frame.size.width
@Glideh
Glideh / fabfile.py
Created September 17, 2012 14:26
A pretty fabfile to deploy a symfony2 project
from fabric.api import *
from fabric.colors import green
env.hosts = ['my_user@my_host']
env.password = 'my_password'
env.app_path = 'my/app/path'
def commit():
print(green("Commit last modifs..."))
local('git add -A && git commit')
@Glideh
Glideh / typeahead_with_id.js
Created September 17, 2012 12:57 — forked from ruslanas/typeahead_with_id.js
Typeahead with id
/*
* CakePHP Twitter Bootstrap Typeahead with id
* ProjectsController.php
* <?php $this->set('projects', $this->Project->find('list'); $this->render('list', 'ajax'); ?>
* /app/View/Projects/list.ctp
* <?php echo json_encode($projects); ?>
* data = {'id': 'item name', ..};
* /app/View/Tasks/index.ctp
* <input type="hidden" id="TaskProjectId" name="data[Task][project_id]"/>
* <input autocomplete="off" data-provide="typeahead" class="typeahead" type="search" id="TaskProject">