Skip to content

Instantly share code, notes, and snippets.

View makerj's full-sized avatar
💗

Junhee Lee makerj

💗
View GitHub Profile
@makerj
makerj / .htaccess
Created January 28, 2016 18:39 — forked from fabiocicerchia/.htaccess
Apache - PUT - 405 Method Not Allowed
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.+$ - [NC,L]
RewriteCond %{REQUEST_METHOD} (PUT|DELETE)
RewriteRule .* put.php
How about recursion? that makes it simple. for example,
**generators.py**
```
def gen_arrayfield(base_field, size, generate_value):
array = []
for _ in range(size):
array.append(generate_value(base_field))
return array
gen_arrayfield.required = ['base', 'size']
@makerj
makerj / model.py
Last active February 7, 2016 18:20
custom django user model
class UserManager(BaseUserManager):
def create_user(self, username, password=None):
"""
Creates and saves a User with the given username and password
"""
if not username:
raise ValueError('Users must have an email address')
user = self.model(
username=username,
@api_view(['GET', 'POST'])
def login_facebook(request):
"""
login via facebook
PREREQUISITES: getting 'code' at frontend using oauth uri like this:
https://www.facebook.com/dialog/oauth?client_id=563193193877116&response_type=code&scope=user_friends,public_profile,email&redirect_uri=http://api.phople.us/login_facebook
:param request: request
:return: login result
def sendmail(recipients, anime, content):
"""
Send email to recipients
:param recipients: recipients
:param anime: animation info
:param content: io.StringIO object messages
:return: None
"""
if 1 == 1: # TODO Remove this dev option
return
@makerj
makerj / python-json.md
Created February 9, 2016 06:16
Hello!

#Python JSON

JSON은 정보나 객체를 전달하기 위한 표준으로, RFC 7159와 ECMA-404에 명세되어 있다.

파이썬은

  1. 표준라이브러리 차원에서 강력한 JSON 컨버터 제공
  2. 파이썬 타입과 JSON타입의 유사성

이라는 장점이 있어 쉽게 JSON과 친해질 수 있다.

@makerj
makerj / #Python zip archive of a directory.md
Last active February 9, 2016 06:26
#Python zip archive of a directory

#Python zip archive of a directory

디렉토리를 .zip 파일로 압축하는 것은 자주 있는 일이다. 짧은 코드로 글을 정리한다. 참조

##무압축


방법은 zipfile, shutil 모듈을 사용한 방법으로 나뉜다. 결과는 같으나 편리함이 다르다.

@makerj
makerj / python-itertools.md
Created February 9, 2016 12:29
#Python itertools

#Python itertools 공식문서를 참조했다.

itertools는 반복 행위가 필요한 부분을 빠르고, 효율적으로 구현할 수 있도록 한다. operator 모듈과도 궁합이 좋다.

##Cheat Sheet


@makerj
makerj / Python argparse.md
Created February 9, 2016 15:22
#Python argparse

#Python argparse 공식 문서를 참조했다.

커맨드라인 인터페이스를 갖는 프로그램을 만들 때, 자주 사용되는 것은 역시나 command line arguments다. C에 optget()이 있다면, Python은 argparse가 있다.

자질구레한 작은 예제 말고 큰 예제로 한눈에 사용법을 익혀보자.

##Cheat Sheet


@makerj
makerj / #Python global variable.md
Last active February 10, 2016 04:59
#Python global variable

#Python global variable 이곳 저곳 참고했다.

SyntaxWarning: name '변수명' is assigned to before global declaration

뭐 결론부터 말하자면 이렇다 if, while, for, try새 블록을 만들지 않는다. 즉 새 local scope를 만들지 않기 때문에 여전히 글로벌인 것이고, 쓸 데 없이 global을 선언해서 파이썬 인터프리터는 어리둥절행이 된 것이다.

주로 이런 일이 일어나는 경우 2가지를 정리해봤다. ###if name == 'main':