Skip to content

Instantly share code, notes, and snippets.

@av-jok
av-jok / del.php
Created February 10, 2018 19:16 — forked from ig0r74/del.php
Удаление старых версий пакетов MODX (запускать из консоли "php del.php")
<?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>';
}
@julienbourdeau
julienbourdeau / wilson.php
Last active August 13, 2024 12:55
[PHP] 5 Star Rating - Lower bound of Wilson score confidence interval for a Bernoulli parameter
<?php
/*
|--------------------------------------------------------------------------
| 5 Star Rating
|--------------------------------------------------------------------------
|
| Lower bound of Wilson score confidence interval for a Bernoulli parameter (0.9604)
|
| See:
@rgrwkmn
rgrwkmn / cache.js
Created January 28, 2016 16:54
Simple JS cache class. Use cache.get to get the value of a key from the cache and provide a function for getting what should be there if it doesn't exist yet or the cache has expired.
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
@66Ton99
66Ton99 / DateTime.php
Last active May 16, 2024 05:31
DateTime
<?php
namespace MyNamespace;
/**
* @author Ton Sharp <66Ton99@gmail.com>
*/
class DateTime extends \DateTime
{
/**
* @param int|null $year
@cmsx
cmsx / VideoThumb.php
Last active February 27, 2024 16:38
Класс для получения превью и информации о ролике RuTube, Vimeo, Youtube по ссылке.
<?php
/**
* Использование:
* $v = new VideoThumb($link);
* $v->getVideo(); //Ссылка на видео
* $v->getTitle(); //Название ролика
* $v->fetchImage($path) //Скачать самое большое превью ролика
*
* Прогнать тест:
@Fi1osof
Fi1osof / modcli.php
Created December 29, 2012 21:52 — forked from Mark-H/a readme.md
<?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
*/
@aknosis
aknosis / calendar.twig
Created October 22, 2012 15:52
Table based calendar only using Twig
{#
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:
@tentacode
tentacode / list.html.twig
Created October 15, 2012 12:23
Twig recursive macro
{% 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>
@stojg
stojg / parse-xml.php
Last active November 18, 2022 21:31
Parsing a huge XML with closure in PHP
<?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