Skip to content

Instantly share code, notes, and snippets.

@allieus
allieus / custom_decorators.py
Created August 13, 2011 07:49
django decorator : logged user are denied
from django.http import HttpResponseForbidden
from django.contrib.auth.models import AnonymousUser
from django.shortcuts import redirect
def deny_logged_user(fn):
def wrap(request, *args, **kwargs):
# if isinstance(request.user, AnonymousUser):
if request.user.is_authenticated():
return fn(request, *args, **kwargs)
# TODO for logged user
@allieus
allieus / gist:1177949
Created August 29, 2011 07:37
jQueryMobile pagebeforeshow test
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>jQueryMobile Test</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" />
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
@allieus
allieus / extend.py
Created August 30, 2011 02:37
Update for ONLY changed fields
from django.db import models
class ChangedOnlySaveModel(models.Model):
def __init__(self, *args, **kwargs):
models.Model.__init__(self, *args, **kwargs)
self._initial_data = self.__dict__.copy()
def save(self, commit=True):
if not self.pk:
models.Model.save(self, commit)
@allieus
allieus / gist:1180047
Created August 30, 2011 02:44
구글맵v3, 위도/경도 좌표를 지도상의 픽셀 상대좌표로 변환하기
//
// 구글맵v3 상에서 위도/경도 좌표를 지도 상의 픽셀 상대좌표로의 변환은 단순히
// projection 의 fromLatLngToPoint 만을 호출해서는 해결되지 않는다.
// 추가적으로 지도 레벨에 대한 처리가 필요하다.
//
// google-maps-js-api-v3
// (http://www.mail-archive.com/[email protected]/msg08752.html)
// 메일링 에서 그 해답을 찾을 수 있었다.
//
// 구글맵 기본 API에서 지원해주면 좋겠는데.
@allieus
allieus / gist:1180051
Last active June 25, 2022 18:10
wgs84/tm127/tm128/grs80/cyworld 간 좌표변환
'''
aero님께서 구현하신 구글/네이버/싸이월드/콩나물 좌표변환은 펄/자바스크립트로 되어있습니다.
펄/자바스크립트에 익숙지 않은지라, 수식을 파이썬으로 번역해보았습니다.
'''
from pyproj import Proj
from pyproj import transform
WGS84 = { 'proj':'latlong', 'datum':'WGS84', 'ellps':'WGS84', }
@allieus
allieus / gist:1574944
Created January 7, 2012 14:53
run django-script from shell
# coding: utf-8
from django.core.management import setup_environ
import settings
setup_environ(settings)
# blah blah ...
@allieus
allieus / custom-style.scss
Created March 14, 2012 05:32
Ext.field.Slider 스타일 바꿔보기
.x-field {
&.x-slider-field {
min-height: 1.4em;
& .x-component-outer {
padding: 0.1em;
}
}
}
.x-slider {
height: 1.1em;
@allieus
allieus / gist:3400746
Created August 20, 2012 04:13
Python Generator 을 이용해서 CSV, XSLX 생성해보기
from openpyxl import Workbook
import random
def get_row_data():
for i in xrange(1000):
rand_num = random.randint(0, 100)
yield (i, (i, rand_num, i + rand_num))
def write_to_csv(filepath):
with open(filepath, 'wt') as f:
@allieus
allieus / gist:3754627
Created September 20, 2012 08:15
FileInput Widget for iOS6 Safari
class Post(models.Model):
photo = models.ImageField(upload_to='photos/%Y/%m/%d')
class PostForm(forms.ModelForm):
class Meta:
model = Post
widgets = {
'photo': forms.FileInput(attrs={'multiple':'multiple', 'accept':'image/*'}),
}
@allieus
allieus / views.py
Last active December 10, 2015 00:29
Django 에서 json.JSONEncoder 에 datetime 형식 추가
import json
from datetime import datetime
from django.http import Http404
from django.http import HttpResponse
class DateTimeJSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime):
return obj.strftime('%Y-%m-%d %H:%M') # FORMAT