Skip to content

Instantly share code, notes, and snippets.

@huanlin
huanlin / azure-openai-example.cs
Created October 14, 2023 12:48
Azure OpenAI C# example
using Azure;
using Azure.AI.OpenAI;
var key = "0bc0xxxxxxxxxxxxxxxx7971";
var endpoint = "https://my-demo-ai-app.openai.azure.com/";
var deployment = "turbo-michael-35";
Console.Write("Ask me anything: ");
var prompt = Console.ReadLine();
@huanlin
huanlin / openai-request-example.txt
Last active October 14, 2023 12:36
OpenAI API request example
@API_KEY = 0bc0xxxxxxxxxxxx7971
@RESOURCE_NAME = my-demo-ai-app
@DEPLOYMENT_ID = turbo-michael-35
### OpenAI Test
POST https://{{RESOURCE_NAME}}.openai.azure.com/openai/deployments/{{DEPLOYMENT_ID}}/chat/completions?api-version=2023-05-15
api-key: {{API_KEY}}
{
"messages": [
@huanlin
huanlin / mudblazor-fonts-and-css.html
Created December 22, 2022 06:13
mudblazor-fonts-and-css.html
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<link href="_content/MudBlazor/MudBlazor.min.css" rel="stylesheet" />
@huanlin
huanlin / MainLayout.razor
Created December 16, 2022 08:32
Blazor app MainLayout.razor
@inherits LayoutComponentBase
<div class="page">
<div class="sidebar">
<NavMenu />
</div>
<main>
<div class="top-row px-4">
<a href="https://docs.microsoft.com/aspnet/" target="_blank">About</a>
@huanlin
huanlin / Index.razor
Created December 16, 2022 08:28
Blazor app Index.razor
@page "/"
<PageTitle>Index</PageTitle>
<h1>Hello, world!</h1>
Welcome to your new app.
<SurveyPrompt Title="How is Blazor working for you?" />
@huanlin
huanlin / App.razor
Created December 16, 2022 08:24
Blazor App.razor
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
@huanlin
huanlin / blazor-program.cs
Created December 16, 2022 03:31
Blazor entry point (Main method)
using BlazorApp.Client;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
@huanlin
huanlin / LineNotifyExample.cs
Created December 1, 2022 14:20
Line Notify Example
namespace ConsoleApp1
{
internal class Program
{
static async Task Main(string[] args)
{
var secretToken = "XYZ"; // <--- Replace with your token.
HttpClient httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", secretToken);
@huanlin
huanlin / maui-create-window.cs
Created November 8, 2022 03:31
MAUI - Create a window
private void Button1_Clicked(object sender, EventArgs e)
{
var win = new Window
{
Page = new NewPage1(),
Width = 1024,
Height = 300 // 亦可在此設定初始座標 X 和 Y
};
Application.Current.OpenWindow(win);
@huanlin
huanlin / maui-change-window-size-position.cs
Last active October 28, 2022 17:54
Change size and position when a window is activated. For MAUI on Windows platform.
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new AppShell();
}
protected override Window CreateWindow(IActivationState activationState)