Skip to content

Instantly share code, notes, and snippets.

@mxp44
mxp44 / delete_older_than.php
Created November 15, 2023 07:23 — forked from hussnainsheikh/delete_older_than.php
A simple PHP function to delete files older than a given age. **Updated to delete files in subdirectories.**
<?php
/**
* A simple function that uses mtime to delete files older than a given age (in seconds)
* Very handy to rotate backup or log files, for example...
*
* $dir String whhere the files are
* $max_age Int in seconds
* return String[] the list of deleted files
*/
@mxp44
mxp44 / delete_older_than.php
Created November 15, 2023 07:23 — forked from tdebatty/delete_older_than.php
A simple PHP function to delete files older than a given age. Very handy to rotate backup or log files, for example...
<?php
/**
* A simple function that uses mtime to delete files older than a given age (in seconds)
* Very handy to rotate backup or log files, for example...
*
* $dir String whhere the files are
* $max_age Int in seconds
* return String[] the list of deleted files
*/
@mxp44
mxp44 / purge_cf.php
Created December 6, 2022 23:46 — forked from Greg-Boggs/purge_cf.php
PHP code to Purge Cloudflare Cache
<?php
// Replace EMAIL/API_KEY/ZONE_ID with your details.
// Zone ID is on the dashboard for the domain in the bottom right.
// Api keys are generated from the account settings. You must give cache purge permissions
// Place this script on your webserver and point a Github Webhook at it, and you'll clear
// the Cloudflare cache every time you do a push to GH.
try {
$head = [];
$head[] = 'Content-Type: application/json';
@mxp44
mxp44 / parse-csv.php
Created April 27, 2022 19:48 — forked from benbalter/parse-csv.php
Parse CSV into Associative Array
<?php
$lines = explode( "\n", file_get_contents( 'input.csv' ) );
$headers = str_getcsv( array_shift( $lines ) );
$data = array();
foreach ( $lines as $line ) {
$row = array();
foreach ( str_getcsv( $line ) as $key => $field )
@mxp44
mxp44 / gist:a06812ea78d2babeeffa61bb4f7d4a04
Created April 25, 2021 01:46 — forked from bryhal/gist:4129042
MYSQL: Generate Calendar Table
DROP TABLE IF EXISTS time_dimension;
CREATE TABLE time_dimension (
id INTEGER PRIMARY KEY, -- year*10000+month*100+day
db_date DATE NOT NULL,
year INTEGER NOT NULL,
month INTEGER NOT NULL, -- 1 to 12
day INTEGER NOT NULL, -- 1 to 31
quarter INTEGER NOT NULL, -- 1 to 4
week INTEGER NOT NULL, -- 1 to 52/53
day_name VARCHAR(9) NOT NULL, -- 'Monday', 'Tuesday'...
@mxp44
mxp44 / calendar_table.sql
Created April 25, 2021 01:44 — forked from marciuz/calendar_table.sql
The script create a calendar table, a useful tool for many databases. It is useful and quicker then create on the fly dates.
--
-- See https://www.brianshowalter.com/blog/calendar_tables
-- With 300 kb of
--
--
-- Create the table
--
CREATE TABLE calendar_table (