Skip to content

Instantly share code, notes, and snippets.

def dictify(a, b):
return dict(map(lambda k, v: (k, v), a, b))
class Keeper(object):
_instances = list()
def __new__(cls):
obj = object.__new__(cls)
cls.__init__(obj)
cls._instances.append(obj)
@classmethod
def list_instances(self):
@pikhovkin
pikhovkin / html_template.html
Created September 11, 2011 20:35
HTML template
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="keywords" content="">
<meta name="description" content="">
<title></title>
<link type="text/css" rel="stylesheet" href="">
<script type="text/javascript" src=""></script>
@pikhovkin
pikhovkin / gist:1210146
Created September 11, 2011 21:20
middle rubber column
#container{width:100%;height:20px;}
#left{width:300px;float:left;}
#main{margin:0 200px 0 300px;text-align:right;padding-right:20px;}
#right2{width:200px;float:right;}
<div id="container">
<div id="left">Col1</div>
<div id="right2">Col3</div>
<div id="main">Rubber col2</div>
</div>
@pikhovkin
pikhovkin / number_human.py
Created March 14, 2012 20:49
Converts an integer or floating-point number or a string to a string containing the delimiter character (default comma) after every delimeter_count digits (by default 3 digits)
from django.template import Library, Node
register = Library()
@register.simple_tag
def number_human(value, separator=',', precision=2, delimeter_count=3, decimal_separator='.'):
""" Converts an integer or floating-point number or a string to a string
containing the delimiter character (default comma)
after every delimeter_count digits (by default 3 digits).
@pikhovkin
pikhovkin / weasyprint_complex_headers.py
Last active February 3, 2024 17:04
Repeat on each page of complex headers (eg, tables) except the first page
# coding: utf-8
from weasyprint import HTML, CSS
def get_page_body(boxes):
for box in boxes:
if box.element_tag == 'body':
return box
@pikhovkin
pikhovkin / middlewares.py
Last active August 29, 2015 14:06
Django-middleware for auto login in DEBUG mode
# coding: utf-8
from django.contrib import auth
from django.conf import settings
from django.core.exceptions import PermissionDenied
from django.shortcuts import redirect
User = auth.get_user_model()
@pikhovkin
pikhovkin / ifthenelse.py
Last active August 29, 2015 14:08
Parser "if then else" expression
# coding: utf-8
from funcparserlib.lexer import make_tokenizer, Spec
from funcparserlib.parser import (maybe, many, eof, skip, oneplus, fwd,
name_parser_vars, memoize, SyntaxError)
from funcparserlib.util import pretty_tree
from funcparserlib.contrib.common import unarg, flatten, n, op, op_, sometoks
from funcparserlib.contrib.lexer import (make_comment, make_multiline_comment,
newline, space)
@pikhovkin
pikhovkin / drawings.py
Last active March 28, 2020 10:06
Patch for openpyxl 2.1.2 for basic reading images. drawings.py and excel.py are in the patch_reader package
# coding: utf-8
from __future__ import absolute_import
import os.path
from io import BytesIO
from openpyxl.xml.constants import (PACKAGE_WORKSHEET_RELS,
REL_NS,
PACKAGE_RELS,
PACKAGE_IMAGES,
@pikhovkin
pikhovkin / ma.py
Created October 29, 2016 12:23
Test for the Ramax
# -*- coding: utf-8 -*-
__all__ = (
'MyError',
'Parent',
'First',
'Second',
'A',
)