Skip to content

Instantly share code, notes, and snippets.

View enif-lee's full-sized avatar
😁

enif.lee enif-lee

😁
View GitHub Profile
@enif-lee
enif-lee / TracingUtils.kt
Created May 28, 2024 03:21 — forked from monosoul/TracingUtils.kt
DataDog Tracing utils for Kotlin coroutines
import datadog.trace.api.DDTags
import io.opentracing.Span
import io.opentracing.Tracer
import io.opentracing.log.Fields
import io.opentracing.tag.Tags
import io.opentracing.util.GlobalTracer
suspend fun <T : Any, O> T.coRunTraced(
methodName: String,
block: suspend T.(Span) -> O,
@enif-lee
enif-lee / StreamingHandler.kt
Last active May 2, 2024 11:58
Implementation streaming download with spring webflux + fastexcel + databuffer + flow
package com.emotimer.presentation.handler
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.reactive.asPublisher
import kotlinx.coroutines.reactor.awaitSingle
import org.dhatim.fastexcel.Workbook
import org.reactivestreams.Publisher
import org.springframework.core.io.buffer.DataBuffer
import org.springframework.core.io.buffer.DefaultDataBufferFactory
import org.springframework.http.ContentDisposition
@enif-lee
enif-lee / StatementBenchmarks.java
Created January 29, 2023 14:06 — forked from mp911de/StatementBenchmarks.java
R2DBC Postgres benchmarks
/*
* Copyright 2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@enif-lee
enif-lee / TokenHelper.cs
Last active April 4, 2020 23:05
Generate Random Token in c#
public class TokenUtil
{
private const string Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
private static readonly Random Random = new Random();
/// <summary>
/// 랜덤 토큰 생성기, 시작 시간에 의존됨
/// NOTE : 강력한 랜덤 스트링 생성기가 필요하다면
/// https://stackoverflow.com/questions/32932679/using-rngcryptoserviceprovider-to-generate-random-string 참고
/// </summary>
@enif-lee
enif-lee / CryptoUtil.cs
Created March 27, 2020 05:50
C# AES256 encryption and decryption example for using easily.
public class CryptoUtil
{
public static byte[] EncryptAes256(byte[] bytes, byte[] key)
{
using var aes = new RijndaelManaged
{
Key = CreateDeriveBytes(key, 32),
};
aes.GenerateIV();
@enif-lee
enif-lee / CryptoUtil.cs
Created March 27, 2020 05:50
C# AES256 encryption and decryption example for using easily.
public class CryptoUtil
{
public static byte[] EncryptAes256(byte[] bytes, byte[] key)
{
using var aes = new RijndaelManaged
{
Key = CreateDeriveBytes(key, 32),
};
aes.GenerateIV();
@enif-lee
enif-lee / example.sh
Created March 11, 2020 11:34
remove multiple aws log groups on msys2
aws logs describe-log-groups --query 'logGroups[*].logGroupName' --output table | awk '{print $2}' | grep ^/aws/codebuild/Kizuna | while read x ; do MSYS2_ARG_CONV_EXCL=\* aws logs delete-log-group --log-group-name $x; done
@enif-lee
enif-lee / DatabaseHealthCheck.cs
Created January 20, 2020 13:38
ASP.NET Core DbContext Health Check
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
namespace Common.Api.HealthCheck
{
public class DatabaseHealthCheck<TDbContext> : IHealthCheck where TDbContext : DbContext
{
private readonly ILogger _logger;
@enif-lee
enif-lee / Base64Helper.cs
Created October 8, 2019 03:17
C# Safe Base64 Helper with c# 8
public static class Base64Helper
{
/// <summary>
/// Convert to url safe base 64
/// </summary>
/// <param name="base64">base64 string</param>
/// <returns></returns>
public static string ToSafeBase64(string base64)
{
return base64
@enif-lee
enif-lee / AwsS3Helper.cs
Created October 2, 2019 07:19
Upload multipart to AWS S3 Object in .NET Core 3.0
public static class AwsS3Helper
{
public static async Task UploadObjectStreamAsync(
this IAmazonS3 s3Client,
Stream stream,
UploadStreamToS3Request request)
{
async IAsyncEnumerable<UploadPartResponse> UploadAsync(string uploadId)
{
await foreach (var (partStream, index, isLast) in SplitPartsFromStream(stream, request.ParSize))