This file contains hidden or 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
Как написать location в nginx, который срабатывает, если два условия должны выполняться. Логично было бы написать так: | |
if ($http_user_agent ~* "Opera" AND $http_referer ~* "yandex.ru") { | |
bla bla bla | |
} | |
nginx не предусматривает в условиях логические операторы | |
Решение есть в виде хака: | |
set $a ""; |
This file contains hidden or 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 get_by_path(path): | |
''' | |
get python object from path | |
>>> get_by_path('os.path.join') | |
<function join at ...> | |
''' | |
spl = path.split('.') | |
mod = None | |
for n, s in enumerate(spl, start=1): | |
try: |
This file contains hidden or 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
''' | |
Simple usage as cherrypy daemon as example | |
''' | |
import soaplib | |
from soaplib.core.server import wsgi | |
from cherrypy.wsgiserver import CherryPyWSGIServer | |
HOST = "0.0.0.0" | |
PORT = 45124 |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
""" | |
The Pygments reStructuredText directive | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
This fragment is a Docutils_ 0.5 directive that renders source code | |
(to HTML only, currently) via Pygments. | |
To use it, adjust the options below and copy the code into a module | |
that you import on initialization. The code then automatically |
This file contains hidden or 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 make_response_for_xls(xls_content, xls_filename): | |
'''Make xls response by xls_content as binary sttring and xls_filename | |
from django.http import HttpResponse | |
response = HttpResponse(xls_content, mimetype="application/ms-excel") | |
response["Content-Disposition"] = u"attachment; filename=\"{0}\"".format(xls_filename) | |
return response |
This file contains hidden or 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
import wizard | |
order_wizard = wizard.Wizard('order_wizard) | |
@order_wizard.register(step=1, url='/basket/') | |
def basket(request): | |
... | |
@order_wizard.register(step=2, url='/step_1/') | |
def step_1(request): |
This file contains hidden or 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
class KeyAttributeDict(dict): | |
''' | |
>>> kd = KeyAttributeDict({'a':1}) | |
>>> kd['a'] | |
1 | |
>>> kd.a | |
1 | |
''' | |
def __getattribute__(self, name): | |
try: |
This file contains hidden or 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#define OPEN_BRACKET_STATE 1 | |
#define CLOSE_BRACKET_STATE 2 | |
#define NUMBER_STATE 3 | |
#define OPERATOR_STATE 4 | |
char OPERATORS[] = {'/', '*', '-', '+'}; |
This file contains hidden or 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 calc_ean_13_checksum(ean): | |
import math | |
sum = 0 | |
for x, c in enumerate(str(ean)[::-1]): | |
if (x+1) % 2 == 0: | |
sum += int(c) | |
else: | |
sum += int(c) * 3 | |
return int(math.ceil(sum / 10.0) * 10) - sum |
This file contains hidden or 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <unistd.h> | |
#define MAX_INT 9999999 | |
int randint(int from, int to) { | |
return (from + rand() % to); |