http {
...
limit_req_zone $binary_remote_addr zone=reqlimit:10m rate=30r/s;
...
}
server {
...
location / {
...
limit_req zone=reqlimit burst=10 nodelay;
}
}
[Definition]
failregex = limiting requests, excess: .* by zone .*, client: <HOST>
ignoreregex =
[nginx-req-limit]
enabled = true
port = http,https
filter = nginx-req-limit
logpath = /var/www/*/*/logs/error.log # Здесь укажите свой путь к логам виртуального хоста
findtime = 600
maxretry = 10
bantime = 7200
"длина": [слово,слово]
words = txt.replace(/[\.,\?\!\:;\–\(\)]/g, '').toLowerCase().split(/\s+/);
// make dictionary
var db = [];
for( var i = 0; i < words.length; i++) {
word = words[i];
len = word.length;
if(db.length <= len || typeof db[len] == 'undefined') db[len] = [];
if(!~db[len].indexOf(word)) db[len].push(word);
}
function getWords(db, length, n) {
n = n || 3;
var result = [], offset = 0, m;
length = Math.max(0, Math.min(length, db.length));
while( result.length < n) {
m = n - result.length;
if( db[length + offset]) {
result = result.concat( getUpTo(m, db[length + offset]))
}
m = n - result.length;
if( offset && m && db[length - offset]) {
result = result.concat( getUpTo(m, db[length - offset]))
}
m = n - result.length;
if( m === 0) break;
offset++;
if( offset + length > db.length && offset > length) break;
}
return result;
}
function getUpTo(n, arr) {
return arr.slice(0, Math.min(n, arr.length));
}
from collections import namedtuple
Record = namedtuple('Record', 'a, b, c, d, e, f, g, h')
r = Record(*[1]*8)
print(r.a, r.b, r.h)
class O():
pass
o = O()
for attr in 'abcdefgh':
setattr(o, attr, 1)
print(o.a, o.b, o.h)
key = lambda c: ord('Е') + 0.5 if c == 'Ё' else ord(c)
import locale
from functools import cmp_to_key
from collections import OrderedDict
locale.setlocale(locale.LC_ALL, 'Russian_Russia.1251')
a = [{'src': 'Яблоко', 'dst': 2343}, {'src': 'Ананас', 'dst': 323}, {'src': 'Ёжик', 'dst': 3223}]
# Чтобы не вызывать связку cmp_to_key(locale.strcoll) в sorted() многократно
def keyfunc(item, func=cmp_to_key(locale.strcoll)):
return func(item[0])
d = OrderedDict(sorted(((e['src'], e['dst']) for e in a), key=keyfunc))
# Чтобы не вызывать связку cmp_to_key(locale.strcoll) в sorted() многократно
def keyfunc(item, func=cmp_to_key(locale.strcoll)):
return func(item['src'])
sorted(a, key=keyfunc)
from sortedcontainers import SortedDict
d = SortedDict(cmp_to_key(locale.strcoll), {e['src']:e['dst'] for e in a})
from django.utils.datastructures import OrderedSet
a = ['Мышь', 'Дом', 'Home', 'Лом', 'a', 'z']
b = ['Мышь', 'Лом', 'z', 'jo']
OrderedSet(a) & OrderedSet(b)
OrderedSet(['Мышь', 'Лом', 'z'])
clf = RandomForestClassifier(n_jobs=-1)
clf.fit(X_train, y_train)
predict = clf.predict(tfidf_predict.toarray())