This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone --mirror [OriginRepo.git] | |
cd [OriginRepo.git] | |
git remote set-url --push origin [New Repo.git] | |
git push --mirror |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_client_ip(request): | |
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') | |
if x_forwarded_for: | |
return x_forwarded_for.split(',')[0] | |
else: | |
return request.META.get('REMOTE_ADDR') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
class SampleCategoryModel | |
id = primary | |
class SamplePostModel | |
category = foreignkey(SampleCategoryModel) | |
created_at = datetimefield | |
""" | |
from django.db.models import Max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import operator | |
from functools import reduce | |
from django.db.models import Q | |
class QueryBuilder: | |
""" | |
Continuous queryset filtering | |
""" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
from random import SystemRandom | |
def generate_key(field_name, model, size=8): | |
charset = string.ascii_lowercase + string.digits | |
key = ''.join(SystemRandom().choice(charset) for _ in range(size)) | |
is_exist = model._default_manager.filter(**{field_name: key}).exists() | |
while is_exist: | |
key = generate_key(size, model) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
registry = {} | |
class MultiMethod(object): | |
def __init__(self, name): | |
self.name = name | |
self.typemap = {} | |
def __call__(self, *args): | |
# a generator expression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
PackageInfo info = getPackageManager().getPackageInfo("myandroid.package.name", PackageManager.GET_SIGNATURES); | |
for (Signature signature : info.signatures) { | |
MessageDigest md = MessageDigest.getInstance("SHA"); | |
md.update(signature.toByteArray()); | |
DebugLogger.d("=============================="); | |
DebugLogger.d("KeyHash:" + Base64.encodeToString(md.digest(), Base64.DEFAULT)); | |
DebugLogger.d("=============================="); | |
} | |
} catch (PackageManager.NameNotFoundException e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var link = document.querySelector("link[rel*='icon']") || document.createElement('link'); | |
link.type = 'image/x-icon'; | |
link.rel = 'shortcut icon'; | |
link.href = 'http://www.stackoverflow.com/favicon.ico'; | |
document.getElementsByTagName('head')[0].appendChild(link); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#blockContainer { | |
display: -webkit-box; | |
display: -moz-box; | |
display: box; | |
-webkit-box-orient: vertical; | |
-moz-box-orient: vertical; | |
box-orient: vertical; | |
} | |
#blockA { | |
-webkit-box-ordinal-group: 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def export_as_csv_action( | |
description="CSV 파일로 출력", fields=None, exclude=None, header=True, force_fields=None): | |
""" | |
CSV 출력을 하는 Django Admin Action Function \n | |
:param description: Action 에 표시할 문구 | |
:param fields: 출력 할 Model Field(Column) | |
:param exclude: 출력에서 제외할 Model Field | |
:param header: Field(Column) 이름을 첫번째 행으로 출력할지 여부 | |
:param force_fields: Django admin 의 list_display 의 Custom field (문자열) 을 사용할 지 여부 False 인 경우 Model 에 없는 필드는 제외한다. | |
""" |