Skip to content

Instantly share code, notes, and snippets.

@slifin
slifin / latest.php
Last active October 21, 2016 13:23
<?php
/**
* Data type to signify a placeholder.
*/
class Placeholder {}
class_alias('Placeholder', '_');
/**
* Recursive array filter.
*
<?php
/**
* This is a functional duplicate of appointment_get_occurances_new()
*
* Pass this function a schedule and it will return all the dates between $from $to
* where an instance of an appointment will occur. If $from is in the past
* consider querying for what really happened with the instance table.
*
* @param array $instances
* The instances.
<?php
declare(strict_types=1);
class Article {
public $props;
function __construct(int $id, string $title, string $body, DateTime $date) {
$this->props = get_defined_vars();
}
}
@slifin
slifin / article.php
Last active September 17, 2016 13:42
<?php
$valid_articles = array_filter([$article], function(Article $article) {
return $article->props['body'] == 'sexy';
});
@slifin
slifin / gist:a380f8afc2503cba0832a22ff482e6da
Created September 17, 2016 13:37
happy little article
$article;
$article;
<?php
$sellout_articles = array_map(function(Article $article) {
$article->props['body'] .= ' TWITTER FACEBOOK <img src="star.bmp"><scriptz src="twitter-likes.js">';
return $article;
}, $valid_articles);
<?php
$count_sponsor_mentions = array_reduce($sellout_articles, function($count, $value) {
if (strpos($value, 'lootbox') !== FALSE) {
$count++;
}
return $count;
}, 0);
<?php
$count_sponsor_mentions = array_reduce($sellout_articles, function($count, $value) use($sponsors) {
foreach($sponsors as $sponsor) {
if (strpos($value, $sponsor) !== FALSE) {
$count++;
}
}
return $count;
}, 0);
<?php
/**
* Data type to signify a placeholder.
*/
class Placeholder {}
class_alias('Placeholder', '_');
/**
* Implements partial application with placeholder support.
*