Skip to content

Instantly share code, notes, and snippets.

@enagorny
enagorny / gist:53afd22ef4cf0a8d479f
Created November 5, 2014 11:23
display final sqlalchemy generated query
# To display final query with also arguments.
from sqlalchemy.dialects import postgresql
print(query.statement.compile(dialect=postgresql.dialect(), compile_kwargs={"literal_binds": True}))
@enagorny
enagorny / gist:8434016
Created January 15, 2014 10:30
Notify finish long running programs in console. Command will be trated as longrunning if it took >= 10 seconds, and notification performed via `tput bel`
function timer_start {
timer=${timer:-$SECONDS}
}
function timer_stop {
timer_show=$(($SECONDS - $timer))
if [[ $timer_show -ge '10' ]]; then
tput bel
fi
unset timer
@enagorny
enagorny / .hgrc
Created November 3, 2013 12:28 — forked from tkfm-yamaguchi/.hgrc
[ui]
username = ""
verbose = True
[defaults]
glog = --color always
[pager]
pager = LESS='FSRX' less
#ignore = version, help, update, serve, record
@enagorny
enagorny / .bash_profile
Created November 1, 2013 11:03
vagrant .bash_profile
export GREP_OPTIONS='--color=auto'
export GREP_COLOR='1;31'
export HISTCONTROL=erasedups # Ignore duplicate entries in history
export HISTSIZE=100000 # Increases size of history
export HISTIGNORE="&:ls:ll:la:l.:pwd:exit:clear:clr:[bf]g"
shopt -s histappend # Append history instead of overwriting
shopt -s cdspell # Correct minor spelling errors in cd command
shopt -s dotglob # includes dotfiles in pathname expansion
shopt -s checkwinsize # If window size changes, redraw contents
@enagorny
enagorny / sentence_titlecase.py
Created June 27, 2013 12:34
Simple proper capitalize in sentences in string.
import re
text = "SPITFIRE 1950S STYLE CAT EYE WAYFARER SUNGLASSES WITH CLEAR ACETATE FRAME SILVER METAL ARMS BLACK BROW DETAIL AND GREEN LENSES."
rtn = re.split('([.!?] *)', text)
result = ''.join([each.capitalize() for each in rtn])
# print(result)
# Spitfire 1950s style cat eye wayfarer sunglasses with clear acetate frame silver metal arms black brow detail and green lenses.
@enagorny
enagorny / gist:3849657
Created October 7, 2012 21:27
Memory usage in MB in given point of script
import resource
print(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1000)
@enagorny
enagorny / scale.py
Created June 21, 2012 15:24
PIL scale with whitespace adding
def scale(image, max_size, method=Image.ANTIALIAS):
"""
resize 'image' to 'max_size' keeping the aspect ratio
and place it in center of white 'max_size' image
"""
im_aspect = float(image.size[0])/float(image.size[1])
out_aspect = float(max_size[0])/float(max_size[1])
if im_aspect >= out_aspect:
scaled = image.resize((max_size[0], int((float(max_size[0])/im_aspect) + 0.5)), method)
else:
@enagorny
enagorny / gist:2845158
Created May 31, 2012 18:14
python simple logging to file
# initialization
import logging
import logging.handlers
LOGGING_SYSLOG_ADDRESS = '/tmp/log'
LOGGING_FORMATTER = logging.Formatter('%(asctime)s %(levelname)s %(name)s %(message)s')
LOGGING_LEVEL = logging.INFO
LOGGING_LOGGER_WEB = 'artifact3028'
logger_web = logging.getLogger(LOGGING_LOGGER_WEB)
{% load menu_tags sekizai_tags %}
{% for child in children %}
<li class="{% if child.selected %}selected{% endif %}{% if child.ancestor %}ancestor{% endif %}{% if child.sibling %}sibling{% endif %}{% if child.descendant %}descendant{% endif %}">
<span class="menu_item">
{% if child.tpl == "no_page.html" %}
{{ child.get_menu_title }}
{% else %}
<a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title }}</a>
{% endif %}
from menus.base import Modifier
from menus.menu_pool import menu_pool
from cms.models import Page
class JustMenu(Modifier):
"""
Menu modifier that add to node template name of the node page
used to make some page in the menu, just menu items with no links.
"""
post_cut = False