See in action jsfiddle
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
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) |
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
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
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} |
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
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 \ |
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
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); | |
} |
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
/** | |
* @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) { |
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
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)) { |
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
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); |
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
// f(x) = mx + n | |
// f(y) = (y - n) / m | |
var start = { | |
x: 1, | |
y: 12 | |
} | |
var end = { | |
x: 4, | |
y: 0 |
NewerOlder