Skip to content

Instantly share code, notes, and snippets.

@pepijnolivier
pepijnolivier / recursivelyPruneDirectory.php
Created March 8, 2023 09:43
PHP: Recursively delete old files and folder in a given directory
/**
* @param $folderName | The full directory name
* @param $maxAge | Max Age in seconds. 172800 = 2 days.
*/
private function recursivelyPruneDirectory($folderName, $maxAge = 60)
{
$items = array_diff(scandir($folderName), ['.','..']);
foreach ($items as $fileOrFolder) {
@pepijnolivier
pepijnolivier / phpcs_config.sh
Last active May 28, 2020 08:16
SET codesniffer default standard globally
phpcs --config-set default_standard PSR12
@pepijnolivier
pepijnolivier / GenericTransformTrait.php
Last active November 26, 2019 14:57
Useful trait when quickly scaffolding an API using Laravel Fractal transformers. PHP 7.0 compatible. Can be used with `astrotomic/laravel-translatable`.
<?php
namespace App\Traits;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
trait GenericTransformerTrait
{
/**
@pepijnolivier
pepijnolivier / isNumber.js
Created August 12, 2019 13:21
Test whether or not a variable is a number in javascript
function isNumber(input) {
return !isNaN(+input);
}
@pepijnolivier
pepijnolivier / svg-to-png.py
Created May 20, 2019 08:04
SVG to PNG in Python
#
# Usage:
# - have all svg's in a particular folder
# - cd into that folder
# - call the script with the desired size as a parameter
# python svg-to-png.py 500
#
#
import glob
import os
@pepijnolivier
pepijnolivier / getDotProp.js
Created November 21, 2018 12:53
Get a nested object value
function returnDefault(defaultReturn) {
return typeof defaultReturn === 'undefined' ? null : defaultReturn;
}
/**
* Usage:
* const obj = { id: 123, name: "John Doe", info: { married: false, partner: { id: 456, name: 'Mary Brown' } } }
* const defaultValue = '/';
* const dotProp = 'info.partner.name'
*
# -*- coding: utf-8 -*-
# MySQL Workbench Python script
#
# <description>
# Written in MySQL Workbench 6.3.6
# Fetch all tables,
# For each table, add created_at, updated_at, deleted_at timestamps,
# Except for many-to-many tables
# Configurable options:
# addDeletedAt: True / False. Add the deleted_at timestamp column
@pepijnolivier
pepijnolivier / NearestValue.php
Created June 20, 2017 08:56
Finds the 'nearest value' of a needle in a SORTED numeric array (ascending). Via https://stackoverflow.com/a/22375510/237739
<?php
/**
* Class NearestValue
* Finds the 'nearest value' of a needle in a SORTED numeric array (ascending)
* Via https://stackoverflow.com/a/22375510/237739
*
* Usage:
* $array = [1000,2000,3000,4000,5000];
* $needle = 1337;
@pepijnolivier
pepijnolivier / ensure_valid_id_types.py
Last active October 31, 2020 12:48
Mysql Workbench script to ensure all id columns and foreign keys are unsigned integers. All ID columns should also be auto-incremental
# -*- coding: utf-8 -*-
# MySQL Workbench Python script
#
# <description>
# Written in MySQL Workbench 6.3.6
import grt
# get a reference to the schema in the model. This will get the 1st schema in it.