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
def compress_route(route): | |
compressed = [] | |
for point in route: | |
compressed.append(point) | |
if len(compressed) >= 3 and is_collinear(*compressed[-3:]): | |
del compressed[-2] | |
return compressed | |
def is_collinear(a, b, c): |
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
SELECT | |
TO_CHAR(NOW(), 'YYYY-MM-DD') || | |
'T' || | |
TO_CHAR(NOW(), 'HH:MM:SS') || | |
'+' || | |
LPAD(EXTRACT(timezone_h from NOW())::TEXT, 2, '0') || | |
':' || | |
LPAD(EXTRACT(timezone_m from NOW())::TEXT, 2, '0') | |
; |
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())); |
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
$('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 | |
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
<?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
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
<!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
<?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 | |
* |
NewerOlder