Skip to content

Instantly share code, notes, and snippets.

@w495
w495 / aggregate_concat.py
Last active April 18, 2017 17:09 — forked from ludoo/aggregate_concat.py
Django aggregates GROUP_CONCAT support for MySQL
"""
From http://harkablog.com/inside-the-django-orm-aggregates.html
with a couple of fixes.
Usage: MyModel.objects.all().annotate(new_attribute=GroupConcat('related__attribute', separator=':')
"""
from django.db.models import Aggregate
from django.db.models.sql.aggregates import Aggregate as SQLAggregate
@etrushkin
etrushkin / cyrillic2latin_file_renamer.py
Last active May 17, 2018 23:40 — forked from ramanqul/cyrillic2latin_file_renamer.py
Cyrillic to Latin File Changer
#!/usr/bin/python
# -*- coding: utf-8 -*-
# http://stackoverflow.com/questions/5574702/how-to-print-to-stderr-in-python
from __future__ import print_function
import sys
def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)
import errno
@w495
w495 / graphite-log-parser.py
Last active November 11, 2015 13:12
Graphite log simple parser for enhancing functions' calls and its' arguments from nginx log.
# -*- coding: utf8 -*-
#
# Graphite log simple parser.
# It parse functions and its arguments using python ast-tree.
#
# For each log line like:
# {
# 192.168.14.20 [23/Jul/2015:15:44:11 +0100]
# "GET /render?from=-4hours&noCache=True&hideLegend=False
@ludoo
ludoo / aggregate_concat.py
Created October 28, 2014 13:18
Django aggregates GROUP_CONCAT support for MySQL
"""
From http://harkablog.com/inside-the-django-orm-aggregates.html
with a couple of fixes.
Usage: MyModel.objects.all().annotate(new_attribute=Concat('related__attribute', separator=':')
"""
from django.db.models import Aggregate
from django.db.models.sql.aggregates import Aggregate as SQLAggregate
@w495
w495 / magic_buffer.c
Created June 1, 2012 16:00
Пример использования библиотеки libmagic
/**
@file magic_buffer.c
Пример использования библиотеки libmagic.
Ниже показано как собирать и тестировать файл:
$> gcc magic_buffer.c -lmagic -I/usr/include/magic -Wall -o magic_buffer
$>./magic_buffer "asas" 2> errr
text/plain
$>./magic_buffer "<?xml version="1.0" encoding="utf-8"?><x>абырвалг</x>"
application/xml
$>./magic_buffer "<?xml"
@nobonobo
nobonobo / subproc_pipe.py
Created March 29, 2012 08:34
nonblocking pipe for subprocess
#!/usr/bin/env python
# encoding: utf-8
import sys
import os
import fcntl
import shlex
from time import sleep
from subprocess import Popen, PIPE