Skip to content

Instantly share code, notes, and snippets.

<?php
//yikes
class ArrayArrayObject extends ArrayObject
{
public function offsetSet($index, $value)
{
array_map(function ($k) use ($value) {
parent::offsetSet($k, $value);
}, (array)$index);
@willemwollebrants
willemwollebrants / BeHolidays.php
Last active December 17, 2019 19:21
Gets a list of all official holidays in Belgium
<?php
use DateTimeImmutable;
use DateInterval;
use DateTimeZone;
use IteratorAggregate;
use ArrayIterator;
class BeHolidays implements IteratorAggregate
{
<?php
namespace Studiow\Util;
class MatchAll
{
private $result;
private $matches = [];
public function __construct($pattern, $subject, $flags = PREG_PATTERN_ORDER, $offset = 0)
vagrant global-status | grep running | cut -c 1-9 | while read line; do echo $line; vagrant halt $line done;
<?php
use Valitron\Validator;
$data = ['contact_number' => '', 'email_id' => ''];
//add data with the keys you want to check
$data['contact_info'] = [
'contact_number', 'email_id'
];
@willemwollebrants
willemwollebrants / .htaccess
Last active February 26, 2016 16:26
Glide + GlideFormats + HTTP
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
@willemwollebrants
willemwollebrants / composer.json
Created February 24, 2016 20:21
Clear cache on composer update or package install
{
"scripts": {
"post-update-cmd": "rm -rf cache/*",
"post-package-install": "rm -rf cache/*"
}
}
@willemwollebrants
willemwollebrants / Overlap.php
Last active December 17, 2019 19:21
Given multiple periods of time in a day, that may overlap, calculate the sum of all the periods, in hours.
<?php
//24 hours in one day, plus an extra hour to count any minutes past midnight
$totals = array_fill_keys(range(0, 24), array_fill_keys(range(0, 59), 0));
//loop through the ranges
foreach ($ranges as $range) {
$start = (int) $range[0]->format('H');
//the duration of this range
$delta = $range[1]->diff($range[0]);