Configure PHP Lumen 5 HTTP Exception Handlers with common JSON responses.
Copy (replace) only the attached files to their respective directories. app/Exceptions/Handler.php
and app/Http/Middleware/Authenticate.php
// f(x) = mx + n | |
// f(y) = (y - n) / m | |
var start = { | |
x: 1, | |
y: 12 | |
} | |
var end = { | |
x: 4, | |
y: 0 |
function slugify($text) | |
{ | |
// replace non letter or digits by - | |
$text = preg_replace('~[^\pL\d]+~u', '-', $text); | |
// transliterate | |
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); | |
// remove unwanted characters | |
$text = preg_replace('~[^-\w]+~', '', $text); |
function scanDir($dir, $contains = null, $sort = 'date', $order = 'ASC', $ignored = array('.', '..', '.htaccess')) | |
{ | |
$files = array(); | |
$finfo = finfo_open(FILEINFO_MIME_TYPE); | |
// die('/'.$contains.'(\D)/'); | |
foreach (scandir($dir) as $i => $file) { | |
if (in_array($file, $ignored)) { |
/** | |
* @param string $fileName | |
* @param string $mime | |
* @param bool $download | |
* @param string $path | |
* @return mixed | |
*/ | |
function fileProxy($fileName, $mime = 'auto', $download = false, $path = '/some/folder/') | |
{ | |
if (basename($fileName) != $fileName) { |
import _ from 'lodash'; | |
// usage: _.removeDeepByKey(someObject, 'unwantedKey'); | |
_.mixin({ | |
'removeDeepByKey': function(obj, keyToBeRemoved) { | |
return _.transform(obj, function(result, value, key) { | |
if (_.isObject(value)) { | |
value = _.removeDeepByKey(value, keyToBeRemoved); | |
} |
FROM php:7.2-fpm | |
RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" | |
RUN apt-get update && apt-get install -y --no-install-recommends \ | |
libmcrypt-dev mysql-client libmagickwand-dev git zip \ | |
ghostscript imagemagick libmagickwand-dev \ | |
&& rm -rf /var/lib/apt/lists/* | |
RUN pecl install imagick mcrypt-1.0.1 \ |
FILE=/tmp/worker.nodes | |
touch ${FILE} || exit | |
for node in `docker node ls --filter role=worker -q`; do | |
if grep -Fxq "${node}" ${FILE} | |
then | |
echo "This node ${node} already exists" | |
else | |
echo "This node ${node} joined recently, so rebalance" | |
for service in `docker service ls -q`; do | |
docker service update --with-registry-auth --detach=true --force ${service} |
Configure PHP Lumen 5 HTTP Exception Handlers with common JSON responses.
Copy (replace) only the attached files to their respective directories. app/Exceptions/Handler.php
and app/Http/Middleware/Authenticate.php
See in action jsfiddle
const run = (cb, repeats, timeout = 100, i = 0) => { | |
cb(i) | |
setTimeout(() => { | |
++ i | |
if (repeats >= i + 1) run(cb, repeats, timeout, i) | |
}, timeout) | |
} | |
run(i => { | |
console.log(i) |