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 / minemap.py
Created January 16, 2011 14:27 — forked from kurokikaze/minemap.py
Render minecraft map from world chunks
from struct import unpack
import Image
tag_types = { 0 : 'End',
1 : 'Byte',
2 : 'Short',
3 : 'Int',
4 : 'Long',
5 : 'Float',
6 : 'Double',
@Apkawa
Apkawa / daemon.py
Created February 17, 2011 09:53
Django daemon
# -*- coding: utf-8 -*-
'''
Новая версия демона, отрефакторенная
class Command(BaseDaemon):
def start_server(self, options):
<some action>
или
import os
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
ICON_PATH = [os.path.join('icons', 'led-icons'), os.path.join('icons', 'clever_icons') ]
ALIASES = {
'add':'add-icon',
'edit':'pencil',
@Apkawa
Apkawa / fields.py
Created June 24, 2011 15:39
copy snippet PickleField and add ZipPickleField Field for large sizing objects
# -*- coding: utf-8 -*-
from django.db import models
import zlib
try:
import cPickle as pickle
except ImportError:
import pickle
from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^b2b\.fields\.PickledObjectField"])
@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"])
@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 / 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 / manage.py
Created June 28, 2011 10:57
Transparenty using virtualenv
#!./virtualenv_python.sh
#some text
@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 youremail@gmail.com yourpassword
python album_fetcher.py https://plus.google.com/118353143366443526186 youremail@gmail.com yourpassword /out_dir/
TODO: use opt parse
'''
import os
@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