Skip to content

Instantly share code, notes, and snippets.

@ModMapper
ModMapper / InterpolatedQuery.cs
Created July 16, 2025 01:12
SQL Query Builder using InterpolatedStringHandler
using System.Runtime.CompilerServices;
using System.Text;
using Microsoft.Data.SqlClient;
Console.Write("Login Id : ");
string loginId = Console.ReadLine() ?? string.Empty;
int UseFl = 1;
SqlQueryHandler handler = $"SELECT * FROM Users WHERE LoginId = {loginId.Trim()} AND UseFl = {UseFl}";
@ModMapper
ModMapper / SessionAuthenticationHandler.cs
Created November 20, 2024 07:17
Session based authentication
using System.Security.Claims;
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.Options;
public class SessionAuthenticationHandler : SignInAuthenticationHandler<SessionAuthenticationOptions>
{
public SessionAuthenticationHandler(IOptionsMonitor<SessionAuthenticationOptions> options, ILoggerFactory logger, UrlEncoder encoder)
: base(options, logger, encoder) {}
@ModMapper
ModMapper / scheduler.js
Created October 31, 2024 07:10
Simple scheduler
function createScheduler(callback, interval = 5000) {
let timerId = setTimeout(scheduleNext, interval); // 타이머 시작
return { run, stop };
function stop() {
clearTimeout(timerId); // 타이머 종료
timerId = null; // 타이머 초기화
}
@ModMapper
ModMapper / getResponseFileName.ts
Created October 8, 2024 05:05
Get FileName Form Response
function getResponseFileName(res : Response) : string {
return getContentFileName(res.headers.get('content-disposition')) || getURLFileName(res.url);
function getContentFileName(contentDisposition : string) {
if (!contentDisposition) return null;
const pattern = /filename\*=UTF-8''([^"';\n]+)|filename[^;\n=]*=["']?([^"';\n]+)["']?/;
const matches = contentDisposition.match(pattern);
if (matches) {
if (matches[1]) {
return decodeURIComponent(matches[1]);
@ModMapper
ModMapper / Stun.cs
Created July 19, 2024 03:11
Google STUN Server Example
using System.Buffers.Binary;
using System.Net;
using System.Net.Sockets;
internal class Program
{
private static void Main(string[] args)
{
var ep = FetchGoogleStunAsync().Result;
Console.WriteLine(ep.Port);
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
public class SimpleCache<T>
{
public SimpleCache(TimeSpan expiry, Func<string, T> dataRetriever)
{
Expiry = expiry;
DataRetriever = dataRetriever;
@ModMapper
ModMapper / utils.js
Last active July 4, 2024 02:32
잡다한 유틸함수
TkUtils = {
escape: {
regex(value) {
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
},
},
parse: {
boolean(value) {
return String(value).toLowerCase() === 'true';
},
<!--[\s\S]*?(-->|$)|<script+([\s\/]+([^=>\s\/]+\s*=\s*("[^"]*"|'[^']*'|[^">\s\/][^>\s\/]*)|[^=>\s\/]+))*[\s\/]*>[\s\S]*?(<\/script+([\s\/]+([^=>\s\/]+\s*=\s*("[^"]*"|'[^']*'|[^">\s\/][^>\s\/]*)|[^=>\s\/]+))*[\s\/]*>|$)|<style+([\s\/]+([^=>\s\/]+\s*=\s*("[^"]*"|'[^']*'|[^">\s\/][^>\s\/]*)|[^=>\s\/]+))*[\s\/]*>[\s\S]*?(<\/style+([\s\/]+([^=>\s\/]+\s*=\s*("[^"]*"|'[^']*'|[^">\s\/][^>\s\/]*)|[^=>\s\/]+))*[\s\/]*>|$)|<\/?[^>\s\/]+([\s\/]+([^=>\s\/]+\s*=\s*("[^"]*"|'[^']*'|[^">\s\/][^>\s\/]*)|[^=>\s\/]+))*[\s\/]*>
@ModMapper
ModMapper / SSE.cs
Created March 14, 2024 02:15
Controller에서 Server Sent Event 사용하기
using System.Text;
using Microsoft.AspNetCore.Mvc;
public class SSEActionResult(IAsyncEnumerable<SSEMessage> messages) : IActionResult
{
public async Task ExecuteResultAsync(ActionContext context)
{
var response = context.HttpContext.Response;
response.ContentType = "text/event-stream";
@ModMapper
ModMapper / BigBuffer.cs
Last active February 26, 2024 07:32
연속적인 큰 버퍼에 대한 처리를 하는 클래스
namespace Utils.BigBuffers;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Buffers;
using System.Threading.Tasks;
using System.Threading;
public class BigBuffer<T> : IDisposable
{