Skip to content

Instantly share code, notes, and snippets.

View Apkawa's full-sized avatar
🌴
On vacation

Apkawa Apkawa

🌴
On vacation
View GitHub Profile
@Apkawa
Apkawa / code_directive.py
Created August 14, 2011 19:54
extending rst2html converter
# -*- coding: utf-8 -*-
"""
The Pygments reStructuredText directive
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This fragment is a Docutils_ 0.5 directive that renders source code
(to HTML only, currently) via Pygments.
To use it, adjust the options below and copy the code into a module
that you import on initialization. The code then automatically
@Apkawa
Apkawa / daemon.py
Created July 26, 2011 07:38
Using soaplib as django views
'''
Simple usage as cherrypy daemon as example
'''
import soaplib
from soaplib.core.server import wsgi
from cherrypy.wsgiserver import CherryPyWSGIServer
HOST = "0.0.0.0"
PORT = 45124
@Apkawa
Apkawa / utils.py
Created July 19, 2011 09:27
Get python object from path
def get_by_path(path):
'''
get python object from path
>>> get_by_path('os.path.join')
<function join at ...>
'''
spl = path.split('.')
mod = None
for n, s in enumerate(spl, start=1):
try:
@Apkawa
Apkawa / nginx.conf
Created July 15, 2011 16:08
Nginx hacks
Как написать location в nginx, который срабатывает, если два условия должны выполняться. Логично было бы написать так:
if ($http_user_agent ~* "Opera" AND $http_referer ~* "yandex.ru") {
bla bla bla
}
nginx не предусматривает в условиях логические операторы
Решение есть в виде хака:
set $a "";
@Apkawa
Apkawa / upi.py
Created July 15, 2011 14:55
Simple Uploader to upi.
-*- coding: utf-8 -*-
'''
http://code.google.com/apis/picasaweb/docs/1.0/developers_guide_python.html
'''
import os
import os.path
import mimetypes
import sys
import logging
import logging.handlers
@Apkawa
Apkawa / album_fetcher.py
Created July 6, 2011 12:40
Fetch google+ album
# -*- coding: utf-8 -*-
'''
Usage:
python album_fetcher.py https://plus.google.com/photos/118353143366443526186/albums/5626152497309725217
python album_fetcher.py https://plus.google.com/118353143366443526186
python album_fetcher.py https://plus.google.com/118353143366443526186 [email protected] yourpassword
python album_fetcher.py https://plus.google.com/118353143366443526186 [email protected] yourpassword /out_dir/
TODO: use opt parse
'''
import os
@Apkawa
Apkawa / manage.py
Created June 28, 2011 10:57
Transparenty using virtualenv
#!./virtualenv_python.sh
#some text
@Apkawa
Apkawa / decorators.py
Created June 27, 2011 09:41
render_to decorator
from django.shortcuts import render_to_response
from django.template import RequestContext
from functools import wraps
def render_to(template_name, title='Main'):
"""
Decorator for Django views that sends returned dict to render_to_response function
with given template and RequestContext as context instance.
If view doesn't return dict then decorator simply returns output.
@Apkawa
Apkawa / loader.py
Created June 27, 2011 09:29
Loading templates by path app.template_name -> app/templates/template_name.html
# -*- coding: utf-8 -*-
import os
import sys
import imp
from django.template.loader import BaseLoader
from django.template.loaders.filesystem import Loader as FileSystemLoader
from django.template.base import TemplateDoesNotExist
from django.conf import settings
@Apkawa
Apkawa / fields.py
Created June 26, 2011 15:08
Image field and get more sizes.
# -*- coding: utf-8 -*-
import os
import Image
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.db.models.fields.files import ImageFieldFile
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^blog\.fields\.AvatarImageField"])