Skip to content

Instantly share code, notes, and snippets.

Avatar

Hyunwoo Shim hwshim0810

View GitHub Profile
View .eslintrc.js
// use this format since .eslintrc is deprecated.
// You can logically derive this format.
module.exports = {
parser: 'babel-eslint',
extends: [
'plugin:flowtype/recommended',
'plugin:jest/recommended',
'plugin:react/recommended',
'eslint-config-airbnb',
@hwshim0810
hwshim0810 / hideOnScroll.js
Created Aug 10, 2019 — forked from hisokakei/hideOnScroll.js
react-native-action-button hide on scroll
View hideOnScroll.js
// 1. Define a state variable for showing/hiding the action-button
state = {
isActionButtonVisible: true
}
// 2. Define variables those will keep track of the current scroll position, height and content height
_listViewOffset = 0
_listViewHeight = 0
_listViewContentHeight = 0
@hwshim0810
hwshim0810 / ec2_function.py
Last active Feb 10, 2020
Get ec2 private ip
View ec2_function.py
import os
def is_ec2_linux():
"""Detect if we are running on an EC2 Linux Instance
See http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html
"""
if os.path.isfile("/sys/hypervisor/uuid"):
with open("/sys/hypervisor/uuid") as f:
uuid = f.read()
@hwshim0810
hwshim0810 / image_util.py
Last active Dec 31, 2018
Create temporary imagefile
View image_util.py
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')
@hwshim0810
hwshim0810 / pre-commit
Created Oct 21, 2018 — 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
View pre-commit
#!/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
View views.py
# 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 / dates.py
Created Jul 6, 2018
Restframework custom timestamp field
View dates.py
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 / blur.kt
Created Jul 3, 2018
android image blur
View blur.kt
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 / className.java
Created Jun 28, 2018
Get launch class name
View className.java
Context context = getContext();
context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()).getComponent().getClassName();
@hwshim0810
hwshim0810 / click.java
Created Jun 26, 2018
Android prevent duplicate click
View click.java
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();
}
});
You can’t perform that action at this time.