Skip to content

Instantly share code, notes, and snippets.

View marazmiki's full-sized avatar

Mikhail Porokhovnichenko marazmiki

View GitHub Profile
@marazmiki
marazmiki / to_ipod.py
Created August 14, 2011 20:29 — forked from dpetzold/to_ipod.py
Convert and video to ipod viewable using ffmpeg capturing the output to a display the encoding progress.
#!/usr/bin/python
import fcntl
import optparse
import os
import progressbar
import re
import select
import shlex
import subprocess
@marazmiki
marazmiki / fabfile.py
Created February 17, 2012 07:46
The Fabric script (fabfile.py) with deploy common implementation
# -*- coding: utf-8 -*-
from fabric.api import cd, hide, settings, show, path, prefix, lcd, require,\
prompt, put, get, run, sudo, local, reboot, open_shell, env, output, \
abort, warn, puts, fastprint, execute
from fabric.contrib.console import confirm
import datetime
import sys
###############################################################################
@marazmiki
marazmiki / gist:1898148
Created February 24, 2012 05:51
Генератор последовательностей
import datetime
import random
import string
def seq_gen(length=5, uppercase=True, lowercase=True, digits=True,
special=True, extra=None):
"""
Returns the sequence of given length consists of specified
group of chars: digits, uppercase, lowercase, punctuation or
custom set.
@marazmiki
marazmiki / gist:1942605
Created February 29, 2012 17:17
Базовый класс для всякого рода "пулов" python-объектов
class PoolBase(object):
def __init__(self):
self.item_stack = []
def register(self, item):
if not self.check_type(item):
raise TypeError, 'The {item} can\'t be registered in {class_name}'.format(
class_name = self.__class__,
item = item.__class__)
class FormData(object):
"""
The object with dictionary of data
"""
data = {}
def as_dict(self, fields=None, exclude=None, override={}):
if fields is not None:
return dict([(f, self.data[f]) for f in fields])
@marazmiki
marazmiki / ffmpeg_runner.py
Created June 29, 2012 03:57
Runs the ffmpeg process and calculates convertation progress in real time
class FFMPegRunner(object):
"""
Usage:
runner = FFMpegRunner()
def status_handler(old, new):
print "From {0} to {1}".format(old, new)
runner.run('ffmpeg -i ...', status_handler=status_handler)
@marazmiki
marazmiki / authuser.md
Created June 30, 2012 19:33 — forked from jacobian/authuser.md
Upgrading auth.User - the profile approach

Upgrading auth.User - the profile approach

This proposal presents a "middle ground" approach to improving and refactoring auth.User, based around a new concept of "profiles". These profiles provide the main customization hook for the user model, but the user model itself stays concrete and cannot be replaced.

I call it a middle ground because it doesn't go as far as refactoring the whole auth app -- a laudable goal, but one that I believe will ultimately take far too long -- but goes a bit further than just fixing the most egregious errors (username length, for example).

This proposal includes a fair number of design decisions -- you're reading the fifth or sixth draft. To keep things clear, the options have been pruned out and on the one I think is the "winner" is still there. But see the FAQ at the end for some discussion and justification of various choices.

The User model

@marazmiki
marazmiki / daemon.py
Created September 4, 2012 07:53
Python daemon example
#!/usr/bin/env python
# coding: utf-8
import argparse
import os
import sys
import time
import atexit
import logging
import signal
@marazmiki
marazmiki / sticky.css
Created November 14, 2012 08:53 — forked from mokagio/sticky.css
Twitter Bootstrap + Sticky Footer + Fixed Nav Bar
html, body, .container, .content {
height: 100%;
}
.container, .content {
position: relative;
}
.proper-content {
padding-top: 40px; /* >= navbar height */
@marazmiki
marazmiki / gist:4214368
Created December 5, 2012 09:50 — forked from michelts/gist:1029336
FormsView
from django.views.generic.base import View, TemplateResponseMixin
from django.views.generic.edit import FormMixin, ProcessFormView
class MultipleFormsMixin(FormMixin):
"""
A mixin that provides a way to show and handle several forms in a
request.
"""
form_classes = {} # set the form classes as a mapping