This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('MODX_API_MODE', true); | |
require 'index.php'; | |
$modx->getService('error', 'error.modError'); | |
$modx->setLogLevel(modX::LOG_LEVEL_ERROR); | |
$modx->setLogTarget('ECHO'); | |
if (!XPDO_CLI_MODE) { | |
echo '<pre>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
|-------------------------------------------------------------------------- | |
| 5 Star Rating | |
|-------------------------------------------------------------------------- | |
| | |
| Lower bound of Wilson score confidence interval for a Bernoulli parameter (0.9604) | |
| | |
| See: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cache { | |
constructor() { | |
this.cache = {}; | |
this.timeouts = {}; | |
} | |
set(key, value, ttl) { | |
this.cache[key] = value; | |
if (ttl) { | |
// instead of using timeouts it could validate the ttl when `get` is called | |
// so the amount of timeouts doesn't get out of control |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyNamespace; | |
/** | |
* @author Ton Sharp <66Ton99@gmail.com> | |
*/ | |
class DateTime extends \DateTime | |
{ | |
/** | |
* @param int|null $year |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Использование: | |
* $v = new VideoThumb($link); | |
* $v->getVideo(); //Ссылка на видео | |
* $v->getTitle(); //Название ролика | |
* $v->fetchImage($path) //Скачать самое большое превью ролика | |
* | |
* Прогнать тест: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* modCLI is a command line interface for MODX Revolution Processors. | |
* | |
* It enables you to run any core or third party processor from the command line, passing it options as you go along. | |
* | |
* @author Mark Hamstra <hello@markhamstra.com> | |
* @version 0.1.0-pl, 2012-12-16 | |
* @license GPL v2 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
time can be any string acceptable by http://www.php.net/strtotime, the | |
template will output that time's month. | |
If you don't want to pass in a date you can set time like this: | |
{% set time = "now"|date("U") %} | |
{% set time = "December 2012"|date("U") %} | |
How ever you want to output items onto the calendar is a different issue, | |
but I'd assume pushing everything into an array numerically indexed by that day: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro recursiveCategory(category) %} | |
<li> | |
<h4><a href="{{ path(category.route, category.routeParams) }}">{{ category }}</a></h4> | |
{% if category.children|length %} | |
<ul> | |
{% for child in category.children %} | |
{{ _self.recursiveCategory(child) }} | |
{% endfor %} | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// An example on how to parse massive XML files with PHP by chunking it up to avoid running out of memory | |
// Open the XML | |
$handle = fopen('file.xml', 'r'); | |
// Get the nodestring incrementally from the xml file by defining a callback | |
// In this case using a anon function. | |
nodeStringFromXMLFile($handle, '<item>', '</item>', function($nodeText){ | |
// Transform the XMLString into an array and |