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 | |
/** | |
* Creates a progress bar | |
* | |
* @param string $template Template to use, available placeholders are %finished, %unfinished, %percent and %eta | |
* @param int $width Width of the progress bar | |
* @return callable A function that renders the bar and takes the percent as only argument | |
*/ | |
function progressBar( |
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 ($) { | |
'use strict'; | |
$.fn.originalRemoveClass = $.fn.removeClass; | |
$.fn.removeClass = function (arg) { | |
if (arg instanceof RegExp) { | |
return this.originalRemoveClass(function (i, css) { | |
var remove = []; | |
$.each(css.split(/\s+/), function (i, cls) { |
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 | |
class PoolManagerException extends Exception {} | |
class PoolManagerInvalidWeightException extends PoolManagerException {} | |
class PoolManagerNodeNotFoundException extends PoolManagerException {} | |
class PoolManagerEmptyException extends PoolManagerException {} | |
/** | |
* Generic pool manager with horizontal scaling in mind | |
* |
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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<style> | |
.emoji { | |
display: inline-block; | |
font-style: normal; | |
position: relative; | |
top: 1px; |
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
curl https://www.packtpub.com/packt/offers/free-learning | grep -A7 dotd-title | tail -1 | xargs -0 osascript sendmail.applescript [email protected] "Today's free eBook" |
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 | |
trait FlagTrait | |
{ | |
/** @var int */ | |
private $flags = 0; | |
/** | |
* @param int $flag | |
* @return bool |
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 | |
require __DIR__ . '/strtounits.php'; | |
assert(strtometers('25000.23 meters') === 25000.23); | |
assert(strtometers('3km, 25.5 meters') === 3025.5); |
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
$('input').keydown(function (e) { | |
e.preventDefault(); | |
var keys = []; | |
e.altKey && keys.push('⌥'); | |
e.ctrlKey && keys.push('⌃'); | |
e.metaKey && keys.push('⌘'); | |
e.shiftKey && keys.push('⇧'); |
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 | |
class Form extends \Phalcon\Forms\Form | |
{ | |
/** | |
* @inheritdoc | |
*/ | |
public function bind(array $data, $entity, $whitelist = null) | |
{ | |
foreach ($this->getElements() as $element) { |
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
/** | |
* Executes a function with a given interval | |
* @arg {function} fn - Function to execute, | |
* @arg {integer} interval - Interval in milliseconds | |
*/ | |
function poll(fn, interval) { | |
fn(() => setTimeout(() => poll(fn, interval), interval)); | |
} | |
poll(retry => $.get('/status').success(res => res.status === 'pending' && retry())); |