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
| from funcy import join | |
| def apply_el(data, el): | |
| if isinstance(el, str): | |
| return {el: data.get(el)} | |
| elif isinstance(el, dict): | |
| return { | |
| k: apply_schema(data.get(k), v) | |
| for k, v in el.items() | |
| } |
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
| In [1]: class T(tuple): pass | |
| In [2]: t = (1, 2) | |
| In [3]: t.__class__ = T | |
| TypeError: __class__ assignment: only for heap types |
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
| # Original code | |
| from funcy import ireductions | |
| def itemcollector(last, x): | |
| if "Node ID" in x: | |
| return x | |
| if "files" not in last: | |
| last["files"] = [] | |
| last["files"].append(x) |
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 re, logging | |
| from django.conf import settings | |
| from django.core.handlers.wsgi import STATUS_CODE_TEXT | |
| req_handler = logging.FileHandler(settings.HOME_DIR + '/logs/requests.log') | |
| req_handler.setLevel(logging.INFO) | |
| formatter = logging.Formatter('[%(asctime)s] %(message)s') | |
| req_handler.setFormatter(formatter) |
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
| proxy_cache_path /home/mediavault/cache-mem levels=2:2 keys_zone=ram:400m inactive=48h max_size=26G; | |
| proxy_cache_path /home/mediavault/cache-ssd levels=2:2:2 keys_zone=ssd:800m inactive=30d max_size=160G; | |
| client_body_temp_path /home/mediavault/cache-mem/tmp; | |
| open_file_cache max=5000 inactive=600s; | |
| open_file_cache_valid 1200s; | |
| open_file_cache_min_uses 2; | |
| open_file_cache_errors on; | |
| server { |
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
| #!/bin/bash | |
| BACKUP_SERVER=kronos.metadesign.ru | |
| BACKUP_DIR=/backup/zeus/all/ | |
| RUAUTO_BACKUP_PATH=/db/dumps/pgsql/ruauto.sql.gz | |
| DUMP_TMP=tmp/db.sql | |
| DUMP_TMP_GZ="$DUMP_TMP.gz" | |
| # Text color variables |
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
| # Предполагая m2m такого вида | |
| class Tag(model.Model): | |
| text = model.CharField() | |
| class News(models.Model): | |
| tags = models.ManyToManyField(Tag) | |
| def index(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
| # Say we have this | |
| class BaseCache(object): | |
| def cached(self, timeout=None): | |
| """A decorator for caching function calls""" | |
| def decorator(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| cache_key = get_key(func, args, kwargs) | |
| try: | |
| result = self.get(cache_key) |
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
| # Just two lines anywhere, still copies data before pickling | |
| import copy_reg | |
| copy_reg.pickle(buffer, lambda b: (buffer, (bytes(b),))) |
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
| alert('Hello world') |