var result = classes.split(' ').filter(function(substr) {
return substr.indexOf('-vol-') < 0;
}).join(' ');
var result = classes.replace(/\s([^\s]+?)-vol-([^\s$]+)/g, '');
var result = classes.replace(/\s([^\s]+?)-vol-([^\s$]+?)\b/g, '');
console.log(
a
.split(/\r?\n/)
.filter(function(line) {
return line.match(/^[^#]/);
})
);
$start = microtime(true);
for($i=0;$i<10000;$i++){
$a = 0;
if ($a < 1) ++$a;
}
$time = microtime(true) - $start;
printf('Time %.4F s.', $time);
$start = microtime(true);
for($i=0;$i<10000;$i++){
$a < 1 && ++$a;
}
$time = microtime(true) - $start;
printf('Time %.4F s.', $time);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('ClassName', 'CallbackMethod'));
и/илиcurl_setopt($ch, CURLOPT_HEADERFUNCTION, 'ClassName::CallbackMethod');
<?php
class QueryDB extends PDO{
private static $_instance = null;
private function __construct ($host, $dbname, $username, $pass) {
parent::__construct('mysql:host=' . $host . ';dbname=' . $dbname, $username, $pass);
}
private function __clone(){}
public static function getInstance($configDB){
if (self::$_instance === null) {
self::$_instance = new self($configDB['host'],$configDB['db'],$configDB['user'], $configDB['pass']);
}else{
return self::$_instance;
}
}
protected function getDbObject(){
return $this->_instance;
}
public function select ($query='', $Parametrs=null) {
$pdo = $this->getDbObject();
$sth = $pdo->prepare($query);
if ($sth->execute($Parametrs)) {
return $sth->fetchAll(PDO::FETCH_ASSOC);
}else{
throw new Exception('Запрос не выполнен');
}
}
public function insert($table='', $fields=array()) {
$pdo = $this->getDbObject();
// для наглядности вообще так делать не стоит
$values = 'VAlUES(';
$keys = '(';
foreach($fields as $key=>$val){
$values .=$val . ',';
$keys .=$key . ',';
}
trim($values,',');
$values .= ')';
trim($keys,',');
$keys .= ')';
// конец лапшы
$sth = $pdo->prepare('INSERT INTO `'.$table.'` '. $keys. ' ' .$values );
return $sth->execute();
}
}
$ python3 -c "import this"
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>> class Test:
a = 5
>>> globals()['Test']()
<Test object at 0x7f73aade9cc0>
import sys
sys.path.append('/module/')
# в папке module есть файл __init__.py и moduleBest.py
# делаем импорт
from module import moduleBest