Skip to content

Instantly share code, notes, and snippets.

View hwshim0810's full-sized avatar

Hyunwoo Shim hwshim0810

View GitHub Profile
@hwshim0810
hwshim0810 / mixin.scss
Created May 20, 2018 14:16
responsive mixin
$tablet-width: 768px;
$desktop-width: 875px;
$xl-desktop-width: 1351px;
$phone-width: 320px;
$iphone6-width: 375px;
$iphone6plus-width: 450px;
@mixin breakpoint($breakpoint) {
@if $breakpoint == "tablet" {
@media (min-width: #{$iphone6plus-width}) and (max-width: #{$desktop-width}) {
@hwshim0810
hwshim0810 / divider.scss
Created May 20, 2018 14:17
Grey line divider
.divider {
text-transform: uppercase;
color: $dark-grey;
font-weight: 600;
margin: 20px 0;
position: relative;
&:before,
&:after {
content: "";
@hwshim0810
hwshim0810 / cookie.js
Created May 24, 2018 07:13
Javascript getCookie functions
@hwshim0810
hwshim0810 / click.java
Created June 26, 2018 04:36
Android prevent duplicate click
private long mLastClickTime = 0L;
findViewById(R.id.button)
.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
// mis-clicking prevention :: 1000 ms
if (SystemClock.elapsedRealtime() - mLastClickTime < 1000) return;
mLastClickTime = SystemClock.elapsedRealtime();
}
});
@hwshim0810
hwshim0810 / className.java
Created June 28, 2018 02:35
Get launch class name
Context context = getContext();
context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()).getComponent().getClassName();
@hwshim0810
hwshim0810 / blur.kt
Created July 3, 2018 15:56
android image blur
import android.content.Context
import android.graphics.Bitmap
import android.os.Build
import android.renderscript.Allocation
import android.renderscript.Element
import android.renderscript.RenderScript
import android.renderscript.ScriptIntrinsicBlur
fun blur(context: Context, sourceBitmap: Bitmap, radius: Float): Bitmap {
@hwshim0810
hwshim0810 / dates.py
Created July 6, 2018 02:33
Restframework custom timestamp field
from django.utils import timezone
from rest_framework import serializers
class DateToTimestampField(serializers.Field):
def to_representation(self, value):
epoch = timezone.datetime(1970, 1, 1)
value = timezone.datetime.fromordinal(value.toordinal())
return int((value - epoch).total_seconds()) * 1000
@hwshim0810
hwshim0810 / views.py
Created October 11, 2018 06:04
Password init
# Views
from rest_framework.generics import CreateAPIView
from rest_framework.response import Response
class PasswordInitializeAPIView(CreateAPIView):
serializer_class = serializers.PasswordInitSerializer
def create(self, request, *args, **kwargs):
self.check_permissions(request)
serializer = self.get_serializer(data=request.data)
@hwshim0810
hwshim0810 / pre-commit
Created October 21, 2018 04:39 — forked from acdha/pre-commit
Git pre-commit hook which runs various code linters. Install this to .git/hooks/pre-commit inside your favorite repos
#!/usr/bin/env PYTHONIOENCODING=utf-8 python
# encoding: utf-8
"""Git pre-commit hook which lints Python, JavaScript, SASS and CSS"""
from __future__ import absolute_import, print_function, unicode_literals
import os
import subprocess
import sys
@hwshim0810
hwshim0810 / image_util.py
Last active December 31, 2018 05:25
Create temporary imagefile
import tempfile
from io import BytesIO
from PIL import Image
def get_test_image():
file = BytesIO()
image = Image.new('RGBA', size=(50, 50), color=(155, 0, 0))
image.save(file, 'png')