Skip to content

Instantly share code, notes, and snippets.

View xfenix's full-sized avatar
😏
All commits are lost

Denis xfenix

😏
All commits are lost
View GitHub Profile
$.fn.followTo = function (pos) {
var $this = this,
$window = $(window);
$window.scroll(function (e) {
if ($window.scrollTop() > pos) {
$this.css({
position: 'absolute',
top: pos
});
class CacheGroup(object):
ttl = 3600
initial = 1
group = ''
def __init__(self, group, ttl):
self.group = group
self.ttl = ttl
def key(self, key):
tree_already_apended = []
tree_childs_key = 'childs'
data = [
dict(
id=1,
parent=None
),
dict(
id=2,
parent=1
@xfenix
xfenix / ExtjsTreeResource.py
Last active December 22, 2015 15:29
Outputs tree resource (add /tree to resource url), cached
class ExtjsTreeResource(ExtJsModelResource):
max_limit = 1000
cache_group = ''
cache_ttl = 3600
cache_url_params = ['offset', 'page', 'limit', 'node']
tree_parent_key = ''
tree_childs_key = 'childs'
tree_id_key = 'id'
def prepend_urls(self):
class UsualCustomResourceTestCase(CustomResourceTestCase):
tested_object = None
resource_object = None
resources = None
created_stack = []
generated_numbers = []
exclude_fields = ['created', 'modified']
exclude_ignore_fields = ['name', ]
username = 'dmitri'
password = '12345'
def str_replace_multi(string, replacements, empty_if_list=True):
try:
iterator = repls.iteritems()
except:
if isinstance(replacements, (list, tuple)):
first = iter(replacements)
second = ['']*len(replacements) if empty_if_list else\
first
iterator = dict(zip(first, second))
else:
@xfenix
xfenix / bash_profile.sh
Last active December 16, 2015 08:09
.bash_profile django & git tweaks
# bash
alias rr=". ~/.bash_profile"
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."
alias c=clear
function freem() {
from django.utils.html import strip_tags, escape
from django.utils.safestring import mark_safe
"""
Strips all [X]HTML tags except the space seperated list of tags
from the output.
Usage: keeptags:"strong em ul li"
"""
def keep_tags(value, tags):
@xfenix
xfenix / rupluralize.py
Last active March 5, 2018 04:25
Russian pluralize django template tag
# pluralize for russian language
# {{someval|rupluralize:"товар,товара,товаров"}}
@register.filter(is_safe = False)
@stringfilter
def rupluralize(value, arg):
bits = arg.split(u',')
try:
value = str( 0 if not value or value <= 0 else value )[-1:] # patched version
return bits[ 0 if value=='1' else (1 if value in '234' else 2) ]
except:
@xfenix
xfenix / drupal_add_column_to_admincontent.php
Created December 14, 2012 12:45
Add column to admin/content for Drupal 7
<?
function MYMODULE_form_node_admin_content_alter(&$form, &$form_state, $form_id) {
$column_alias = 'my_cool_column';
$column_title = 'Header of my cool column';
// Load the nodes. This incurrs very little overhead as
// "$nodes = node_load_multiple($nids);" has already been run on these
// nids in node_admin_nodes(). The static cache will be used instead of
// another db query being invoked
$nodes = node_load_multiple(array_keys($form['admin']['nodes']['#options']));