Skip to content

Instantly share code, notes, and snippets.

View yoonseopshin's full-sized avatar
🏠
Working from home

Yoonseop Shin yoonseopshin

🏠
Working from home
View GitHub Profile
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
#define endl '\n'
#define pb push_back
vector<int> l, r, tree, lazy;
vector<vector<int>> adj;
int N, M, H, o;
@yoonseopshin
yoonseopshin / fileReceiver.js
Last active April 23, 2021 05:27
MQTT File Copy
const mqtt = require("mqtt");
const fs = require("fs");
const client = mqtt.connect("mqtt://localhost");
client.on("connect", function () {
client.subscribe("test");
});
client.on("message", function (topic, message) {
data = JSON.parse(message);
@yoonseopshin
yoonseopshin / string_parser.py
Created May 1, 2021 12:27
파이썬 간단한 문자열 파싱: 줄 단위로 나누고 - 붙임
import re
def trim(line):
return line.replace(" ", "")
def strip_html(data):
p = re.compile(r'<.*?>')
return p.sub('', data)
def make_bullet(line):
@yoonseopshin
yoonseopshin / .gitmessage
Last active June 29, 2021 10:25
Git commit template
# <type>: <subject>
##### Subject 50 characters ################# -> |
# Body Message
######## Body 72 characters ####################################### -> |
# Issue Tracker Number or URL
# --- COMMIT END ---
@yoonseopshin
yoonseopshin / Preference.kt
Created October 14, 2021 06:32
Preference Usage
import android.content.SharedPreferences
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlin.properties.ReadWriteProperty
@yoonseopshin
yoonseopshin / OnThrottleClickListener.kt
Last active December 19, 2021 10:17
Android throttle click extension implementation (for single click)
class OnThrottleClickListener(
private val dispatcher: CoroutineDispatcher,
private val onClickListener: View.OnClickListener,
private val interval: Long,
) : View.OnClickListener {
private var isClickable = true
override fun onClick(view: View) {
if (isClickable) {
@yoonseopshin
yoonseopshin / FlowExt.kt
Created December 19, 2021 11:54
Lifecycle flow extension
fun <T> ComponentActivity.collectLatestLifecycleFlow(flow: Flow<T>, collect: suspend (T) -> Unit) {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
flow.collectLatest(collect)
}
}
}
@yoonseopshin
yoonseopshin / ItemDecorationWithoutLastItem.kt
Created February 13, 2022 10:10
Add RecyclerView divider without last item
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import androidx.recyclerview.widget.RecyclerView
class ItemDecorationWithoutLastItem(private val divider: Drawable) : RecyclerView.ItemDecoration() {
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
super.onDrawOver(c, parent, state)
val left = parent.paddingLeft
val right = parent.width - parent.paddingRight
@yoonseopshin
yoonseopshin / WorkManagerDataExtension.kt
Created March 15, 2022 12:29
WorkManager serialization extension (Parcelable, Serializable)
package com.andevapps.ontv.extension
import android.os.Parcel
import android.os.Parcelable
import androidx.work.Data
import java.io.*
fun Data.Builder.putParcelable(key: String, parcelable: Parcelable): Data.Builder {
val parcel = Parcel.obtain()
try {
@yoonseopshin
yoonseopshin / SecureSharedPreferences.kt
Created March 17, 2022 05:32 — forked from FrancescoJo/SecureSharedPreferences.kt
A SharedPreferences wrapper implementation with encryption/decryption, using CipherHelper implementation.
import android.content.SharedPreferences
/**
* A [android.content.SharedPreferences] wrapper that helps easy reading/writing values.
*
* @author Francesco Jo([email protected])
* @since 22 - Mar - 2018
*/
class SecureSharedPreferences(private val sharedPref: SharedPreferences) {
fun contains(key: String) = sharedPref.contains(key)