View warm.php
<?php | |
$nums = range(0, 5000); | |
foreach ($nums as $i) { | |
$path = __DIR__."/files/c{$i}.php"; | |
if (file_exists($path)) { | |
break; | |
} | |
file_put_contents($path, "<?php\n\nfunction c{$i}() { return {$i}; }\n\n"); |
View propSearch.js
const hasAllProps = function(list, within) { | |
list.forEach(function(e) { | |
if (!within.hasOwnProperty(e) || within[e] == "") { | |
return false; | |
} | |
}); | |
return true; | |
}; | |
const hasAnyProps = function(list, within) { |
View directory-reflection.php
<?php | |
use Roave\BetterReflection\BetterReflection; | |
use Roave\BetterReflection\Reflector\ClassReflector; | |
use Roave\BetterReflection\SourceLocator\Type\DirectoriesSourceLocator; | |
require __DIR__ . '/vendor/autoload.php'; | |
$refSubscriptions = []; |
View datetime.php
<?php | |
foreach (range(1, 12) as $m) { | |
$elStart = new \DateTimeImmutable("2019-{$m}-10 23:50:00", new \DateTimeZone('Europe/London')); | |
$elEnd = $elStart->add(new \DateInterval('PT5H')); | |
$utcStart = $elStart->setTimezone(new \DateTimeZone('UTC')); | |
$utcEnd = $elEnd->setTimezone(new \DateTimeZone('UTC')); | |
printf("E/L: %s / %s, UTC: %s / %s\n", | |
$elStart->format(DATE_RFC822), | |
$elEnd->format(DATE_RFC822), |
View stuff.php
<?php | |
// Return greatest common divider of two numbers | |
function gcd($a, $b) { | |
return $b ? gcd($b, $a % $b) : $a; | |
} | |
// Returns the least common multiple of two or more numbers. | |
function lcm(...$numbers): int | |
{ |
View timer.php
<?php | |
/** | |
* Utility class to enable very simplistic timing. | |
* | |
* Usage example: | |
* | |
* $t = new Timer(); | |
* // do something here | |
* echo $t; |
View limit-textarea.js
<script type="text/javascript"> | |
$(function(){ | |
function wordCount(str, charlist) { | |
var len = str.length, cl = charlist && charlist.length, | |
chr = '', tmpStr = '', i = 0, c = '', wC = 0, reg = '', match = false; | |
var _preg_quote = function(str) { | |
return (str + '').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!<>\|\:])/g, '\\$1'); | |
} | |
var _getWholeChar = function(str, i) { | |
var code = str.charCodeAt(i); |
View sort.js
// From: https://stackoverflow.com/a/36079484 | |
// The unsorted data | |
let data = { | |
a: 'A', | |
c: 'C', | |
b: 'B' | |
}; | |
// Create it sorted |
View ofilter.php
<?php | |
/** | |
* Filter an array of objects. | |
* | |
* You can pass in one or more properties on which to filter. | |
* | |
* If the key of an array is an array, then it will filtered down to that | |
* level of node. | |
* |
View gist:d366e76122f1ad32052d8b82dd2d516c
# first make sure MP4Box is install | |
sudo apt-get install gpac | |
# then run this from the command line | |
for i in *.h264; do MP4Box -add $i ${i%.*}.mp4; done |
NewerOlder