Skip to content

Instantly share code, notes, and snippets.

View artofhuman's full-sized avatar
💭
I use vim, btw

Semyon Pupkov artofhuman

💭
I use vim, btw
View GitHub Profile
@artofhuman
artofhuman / wrap array for json
Created April 17, 2012 07:03
wrap array for json
<?php echo "'" . implode("','", $arTags) . "'"; ?>
@artofhuman
artofhuman / sum_arrays.php
Created April 22, 2012 08:35
sum arrays by keys
function array_mesh() {
// Combine multiple associative arrays and sum the values for any common keys
// The function can accept any number of arrays as arguments
// The values must be numeric or the summed value will be 0
// Get the number of arguments being passed
$numargs = func_num_args();
// Save the arguments to an array
@artofhuman
artofhuman / file_debug.php
Created April 22, 2012 09:04
Debug info to file
function debug($var)
{
ob_start();
print_r($var);
$txt = ob_get_contents();
ob_clean();
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/debug.txt', $txt);
@artofhuman
artofhuman / bx_ignore
Last active October 3, 2015 17:08
ignore for Bitrix
/bitrix/components/clever/empty
/nbproject/private/
/upload/
/nbproject/
.gitignore
.tags
.DS_Store
/bitrix/components/bitrix/
/bitrix/modules/
/bitrix/admin
@artofhuman
artofhuman / age_declension.py
Created July 4, 2012 18:22
Django: Age declension template tag
@register.filter(name="age_declension")
def age_declension(age):
end = ''
num = None
if age >= 5 and age <= 14:
end = 'лет'
else:
num = (math.floor(age/10)*10)
@artofhuman
artofhuman / sort_inclusion_tag.py
Created July 8, 2012 16:19
Django: Sort inclusion tag
@register.inclusion_tag('catalog/sort.html', takes_context = True)
def catalog_sort(context, detail_url):
sort = [
{'name': 'Популярности', 'sort': 'sort'},
{'name': 'Цене', 'sort': 'price', 'active': False},
{'name': 'Названию', 'sort': 'name', 'active': False}
]
if context['request'].GET.get('sort'):
@artofhuman
artofhuman / vertical-align
Created August 24, 2012 07:55
CSS: vertical align
HTML:
<div class="container"> <!-- блок-контейнер -->
<div> <!-- блок с содержанием -->
Элемент, который выравнивается вертикально внутри блока-контейнера.
</div>
<div class="auxiliary"> </div> <!-- пустой вспомогательный блок -->
</div>
CSS:
.container {
display: table-cell;
@artofhuman
artofhuman / same_hieght_cols
Created August 26, 2012 07:39
CSS:cols with same height
CSS
.b-cols_layout_cols_2_same_height .b-cols__col_position_left{
width: 50%;
float:left;
}
.b-cols_layout_cols_2_same_height .b-cols__col_position_right{
width: 100%;
float:left;
margin:0 0 0 100%;
}
@artofhuman
artofhuman / inclusion_tag.py
Created September 10, 2012 04:57
Django inclusion tag
# -*- coding: utf-8 -*-
from django import template
register = template.Library()
@register.inclusion_tag('template.html', takes_context = True)
def tag(context):
pass
years = [str(item.active_from.year) for item in news_list]
dates = list(enumerate(years, start=1))
result_years = [key for key,group in itertools.groupby(dates, key=lambda x: x[1][:11])]