Skip to content

Instantly share code, notes, and snippets.

View ShinJJang's full-sized avatar
🎯
Focusing

shinjjang ShinJJang

🎯
Focusing
View GitHub Profile
@ShinJJang
ShinJJang / gist:37df0f67a5b5523ad41a
Created September 4, 2013 05:43
Django Authentication using an Email Address
# refered from http://www.micahcarrick.com/django-email-authentication.html
# need to settings.py like this,
# AUTHENTICATION_BACKENDS = ('backends.EmailAuthBackend',)
from django.contrib.auth.models import User, check_password
class EmailAuthBackend(object):
"""
Email Authentication Backend
@ShinJJang
ShinJJang / gist:abde260e4f40e9962173
Created October 14, 2013 14:51
django object join exam using foreign key reverse
"""
Purpose for exact match, but this's Partial matches
"""
pks = [ "1", "2", "3", "4" ]
query = reduce(operator.and_, [ Q(comments__pk=x) for x in pks ] )
bundle.data['answer'] = Posts.objects.filter(query).distinct()
@ShinJJang
ShinJJang / gist:eeaa56d24f8061eccdc6
Last active August 29, 2015 13:57
This is Gist
def This_is_Gist
print "not 광주 과학 기술원"
@ShinJJang
ShinJJang / getFrequntlyContacts.java
Created May 26, 2014 07:24
Android to get frequntly contacts
/**
* 자주거는(전화 횟수 기준) 4명을 기본으로 가져옴
* 연락한 횟수 내림차순으로 상위 4개에 대해 View를 만듬
**/
private ArrayList<Contact> getFrequntlyContacts() {
String selection = Contacts.HAS_PHONE_NUMBER + " == ?";
String[] selectionArgs = new String[]{"1"};
ContentResolver cr = context.getContentResolver();
Cursor cur = cr.query(Contacts.CONTENT_URI, new String[]{Contacts._ID, Contacts.DISPLAY_NAME, Contacts.PHOTO_ID, Contacts.TIMES_CONTACTED, Contacts.HAS_PHONE_NUMBER}, selection, selectionArgs, Contacts.TIMES_CONTACTED + " DESC");
@ShinJJang
ShinJJang / switchDeleteItemButtonVisibility.java
Created May 26, 2014 08:44
Android Delete button Visibility
/**
* Parameter의 state(View.VISIBLE, INVISIBLE)에 따라
* 연락처의 각 view에 삭제 버튼의 Visibility를 설정
* @param state 설정할 Visibility(View.VISIBLE, INVISIBLE)
*/
private void switchDeleteItemButtonVisibility(int state) {
ArrayList<Contact> frequentContacts = getFrequntlyContacts();
for (int i = 0; i <= contact_table.getChildCount() - 1; i++) {
TableRow row = (TableRow) contact_table.getChildAt(i);
@ShinJJang
ShinJJang / eachBackground.java
Created May 26, 2014 09:22
Android different background
TableRow last_row = (TableRow) contact_table.getChildAt(contact_table.getChildCount() - 1);
TableRow row;
if (last_row == null || last_row.getChildCount() == 2) {
row = new TableRow(context);
if (last_row != null) {
int color = ((ColorDrawable) last_row.getChildAt(1).getBackground()).getColor();
view.setBackgroundColor(color);
}
} else {
row = last_row;
@ShinJJang
ShinJJang / RoundedImageView.java
Last active August 29, 2015 14:01
Android Rounded(or Circular) ImageView from web
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
public class MLRoundedImageView extends ImageView {
public MLRoundedImageView(Context context) {
super(context);
}
public MLRoundedImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@ShinJJang
ShinJJang / gist:d93b26fe4f277c261b86
Last active August 29, 2015 14:02
Android bug report : CalendarContract Instance query result in today include all day event in yesterday.
device : Nexus 5 4.4.3
I want events in one day. So I use CalendarContract Instance query with start to end time in today. Problem is yesterday all day event in result.
Uri.Builder builder = CalendarContract.Instances.CONTENT_URI.buildUpon();
ContentUris.appendId(builder, Today start time)
ContentUris.appendId(builder, Today end time)
time log here.
@ShinJJang
ShinJJang / harmony.py
Last active August 29, 2015 14:12
블디님이 화성 개념글을 보고 만든 파이썬 코드 Ref: http://www.todayhumor.co.kr/board/view.php?table=music&no=104169&s_no=104169&page=2
# -*- coding: utf-8 -*-
# 블디님이 화성 개념글을 보고 만든 파이썬 코드
# Ref: http://www.todayhumor.co.kr/board/view.php?table=music&no=104169&s_no=104169&page=2
MAJOR_SCALE = ['C','C#','D','D#','E','F','F#','G','G#','A','A#','B' ]
while True:
root = raw_input(u'루트음은?(종료=Q) : ')
root = root.upper()
if root == 'Q':