Skip to content

Instantly share code, notes, and snippets.

View rkttu's full-sized avatar

Jung Hyun Nam rkttu

View GitHub Profile
@rkttu
rkttu / Program.cs
Created August 19, 2025 02:57
Running .NET in the browser without Blazor and csproj
#!/usr/bin/env dotnet
#:sdk Microsoft.NET.Sdk.WebAssembly
#:property OverrideHtmlAssetPlaceholders=true
#:property AllowUnsafeBlocks=true
#:property PublishAot=false
// dotnet run Program.cs
using System.Diagnostics;
using System.Runtime.InteropServices.JavaScript;
@rkttu
rkttu / fibonacci.cs
Created August 13, 2025 08:41
Fibonacci calculation example (Top-Level statement style)
var n = 10;
var fib = new List<long> { 0, 1, };
for (var i = 2; i < n; i++)
fib.Add(fib[i - 1] + fib[i - 2]);
Console.WriteLine($"Fibonacci sequence up to {n} terms:");
Console.WriteLine(string.Join(", ", fib));
@rkttu
rkttu / script.cs
Created August 11, 2025 02:21
Native DLL example that creates an XLSX file that can be run with rundll32.exe
#!/usr/bin/env dotnet
#:package ClosedXML@0.105.0
#:property OutputType=Library
#:property NativeLib=Shared
#:property RuntimeIdentifier=win-x64
#:property AllowUnsafeBlocks=true
// dotnet publish .\script.cs -o bin
// %windir%\system32\rundll32.exe bin\script.dll,EntryA "HelloWorld.xlsx"
// start HelloWorld.xlsx
@rkttu
rkttu / nightcurtain.cs
Created August 7, 2025 07:50
Nightcurtain is a nudge utility that gently encourages sleep by using Windows color filters instead of forcibly blocking the screen like Screen Time on macOS, and is designed to run automatically in conjunction with the Task Scheduler.
#!/usr/bin/env dotnet
#:sdk Microsoft.NET.Sdk
#:property OutputType=WinExe
#:property TargetFramework=net10.0-windows
// This program can be scheduled using Windows Task Scheduler.
// Below are some example `schtasks` CLI commands to register tasks for `nightcurtain.exe`.
//
// 1. Enable color filter every night at 10:00 PM
// schtasks /Create /TN "NightCurtain_Enable" /TR "C:\Path\To\nightcurtain.exe enable" /SC DAILY /ST 22:00 /F
@rkttu
rkttu / ollama-test.linq
Created January 12, 2025 09:26
LINQpad + macOS + Ollama + LG EXAONE + C#
<Query Kind="Statements">
<NuGetReference Prerelease="true">Microsoft.SemanticKernel.Connectors.Ollama</NuGetReference>
<Namespace>Microsoft.SemanticKernel</Namespace>
<Namespace>Microsoft.Extensions.DependencyInjection</Namespace>
<Namespace>Microsoft.Extensions.Logging</Namespace>
<Namespace>Microsoft.SemanticKernel.ChatCompletion</Namespace>
<Namespace>Microsoft.SemanticKernel.Connectors.Ollama</Namespace>
<Namespace>System.Text.Json.Serialization</Namespace>
<Namespace>System.ComponentModel</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
@rkttu
rkttu / GenerateFirstTimeDdl.cs
Created October 17, 2024 02:09
How to generate SQL DDL compatible with the entire model instead of auto-migration
// Package Required: Microsoft.EntityFrameworkCore.Relational
// In this example, I am using the EF Core driver (Pomelo.EntityFrameworkCore.MySql) from the Pomelo Foundation Project to generate DDL for MariaDB.
// However, you can also use any other driver you want (Microsoft SQL Server, Sqlite, Oracle, etc.).
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
using Pomelo.EntityFrameworkCore.MySql;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
@rkttu
rkttu / ModernWinForm.cs
Last active March 25, 2025 13:22
Windows Forms + Generic Host + Dependency Injection + MVVM + Command in .NET 8
/*
<!-- Project Configuration -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>false</UseWPF>
<ImplicitUsings>disable</ImplicitUsings>
@rkttu
rkttu / Dockerfile
Created September 25, 2024 09:28
Create My Own WSL distro with Dockerfile
FROM ubuntu:22.04
RUN sed -i -e 's/archive.ubuntu.com/mirror.kakao.com/g' /etc/apt/sources.list
RUN set -xe \
&& apt -y update \
&& apt -y install apt-utils tzdata locales
ENV TZ=Asia/Seoul
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone
@rkttu
rkttu / garnet-chat-demo.linq
Last active December 20, 2024 04:20
Garnet Technical Demo
<Query Kind="Statements">
<NuGetReference>Microsoft.Extensions.Caching.StackExchangeRedis</NuGetReference>
<NuGetReference>Microsoft.Garnet</NuGetReference>
<Namespace>Garnet</Namespace>
<Namespace>Garnet.server</Namespace>
<Namespace>Garnet.server.Auth.Settings</Namespace>
<Namespace>Microsoft.AspNetCore.Builder</Namespace>
<Namespace>Microsoft.AspNetCore.Http</Namespace>
<Namespace>Microsoft.Extensions.DependencyInjection</Namespace>
<Namespace>StackExchange.Redis</Namespace>
@rkttu
rkttu / local-policy-list.linq
Last active July 5, 2024 08:08
Local Group Policy Enumeration Code Sample
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\System.DirectoryServices.dll</Reference>
<Namespace>Microsoft.Win32</Namespace>
<Namespace>Microsoft.Win32.SafeHandles</Namespace>
<Namespace>System.ComponentModel</Namespace>
<Namespace>System.DirectoryServices</Namespace>
<Namespace>System.Runtime.InteropServices</Namespace>
<Namespace>System.Security.Principal</Namespace>
<Namespace>System.Collections.ObjectModel</Namespace>
</Query>