Из 2х представленных методов валидации, валидация регулярным выражением (regexp.py) выигрывает в 10 раз (speed.py) по скорости у метода парсинга строки по-буквенно(split.py), более компактно выглядит 2 строки против 36 и более поддерживаемо и менее подвержено ошибкам.
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 | |
/* | |
* Логгер | |
* | |
* @param string $txt текст для логгирования | |
*/ | |
function _log($txt){ | |
//print("$txt\n"); | |
} |
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
var bind = function(callee,context){ | |
return (function(){ | |
return callee.apply(context,arguments); | |
}); | |
}; | |
var TestClass = function(options){ | |
this.txt = options.txt; | |
}; | |
TestClass.prototype = { |
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
7 | |
1 -1 | |
0 0 | |
1 1 | |
3 1 | |
3 -1 | |
2 0 | |
4 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
#!/usr/bin/python3 | |
import subprocess | |
import re | |
import time | |
from datetime import datetime | |
#Path to log file | |
LOG_PATH = "/var/log/monitor.memory.log" |
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
/* | |
Условие: | |
Пять безмолвных философов сидят вокруг круглого стола, перед каждым философом стоит тарелка спагетти. | |
Вилки лежат на столе между каждой парой ближайших философов. | |
Каждый философ может либо есть, либо размышлять. | |
Приём пищи не ограничен количеством оставшихся спагетти — подразумевается бесконечный запас. | |
Тем не менее, философ может есть только тогда, когда держит две вилки — взятую справа и слева | |
(альтернативная формулировка проблемы подразумевает миски с рисом и палочки для еды вместо тарелок со спагетти и вилок). | |
Каждый философ может взять ближайшую вилку (если она доступна), или положить — если он уже держит её. | |
Взятие каждой вилки и возвращение её на стол являются раздельными действиями, которые должны выполняться одно за другим. |
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
# opt.sources = "#id1,#id2,#id3" | |
data = _.reduce $(opt.sources),((memo, el)-> | |
$item = $(el) | |
if $item.is("input[type='radio']") | |
if $item.is(":checked") | |
memo[$item.attr("name")] = $item.is(":checked") | |
else if $item.is("input[type='checkbox']") | |
memo[$item.attr("name")] = $item.is(":checked") | |
else | |
memo[$item.attr("name")] = $item.data("value") ? $item.val() |
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
var Service = { | |
factorial: function(val){ | |
var result = 1; | |
for(var i = 1; i<=val; ++i){ | |
result *= i; | |
} | |
return result; | |
}, | |
getNumber:function(value, pos){ | |
if(pos < 0){ return null; } |
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 zip2(keys,values): | |
res = {} | |
it = iter(values) | |
nullValue = False | |
for key in keys: | |
try: | |
res[key] = it.next() if not nullValue else None | |
except StopIteration: | |
nullValue = True | |
res[key] = None |
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
CREATE TABLE users | |
( | |
UID int auto_increment primary key, | |
Name varchar(20) | |
); | |
INSERT INTO users | |
(UID, Name) | |
VALUES | |
(1, 'Платон Щукин'), |