Skip to content

Instantly share code, notes, and snippets.

@ynkdir
ynkdir / phi-silica.py
Created October 19, 2025 09:20
Test Phi Silica
# https://learn.microsoft.com/en-us/windows/ai/apis/phi-silica
import asyncio
from win32more.Microsoft.Windows.AI import AIFeatureReadyState
from win32more.Microsoft.Windows.AI.Text import LanguageModel
from win32more.Windows.ApplicationModel import LimitedAccessFeatures, LimitedAccessFeatureStatus
# You need to obtain LAF access token. See url above.
LAF_FEATURE_ID = ""
@ynkdir
ynkdir / howto-create-packaged-application.md
Last active October 23, 2025 13:07
How to create packaged application.
@ynkdir
ynkdir / msvcp140_dll_incompatible.cpp
Last active September 28, 2025 04:59
There are multiple versions of msvcp140.dll. And they are not forward compatible.
// There are multiple versions of msvcp140.dll.
// If C++ program is compiled with newer version, it will not work with older
// version of msvcp140.dll.
//
// You can check file version with PS> (Get-Item msvcp140.dll).VersionInfo
//
// https://learn.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017?view=msvc-170
// ```
// C++ binary compatibility between Visual Studio versions
// ...
@ynkdir
ynkdir / windows_ml_example.py
Last active September 27, 2025 12:38
Windows ML example
# Load and predict with ONNX Runtime and a very simple model
# https://onnxruntime.ai/docs/api/python/auto_examples/plot_load_and_predict.html
#
# Install
# https://learn.microsoft.com/en-us/windows/ai/new-windows-ml/get-started?tabs=python>
# pip install win32more
# pip install --pre --index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ --extra-index-url https://pypi.org/simple onnxruntime-winml
import asyncio
@ynkdir
ynkdir / memoryview_pointer.py
Created September 20, 2025 14:10
How to get pointer of memoryview (and how to break python object)
# How to get pointer of memoryview (and how to break python object)
from ctypes import *
PyBUF_FULL_RO = 0x0100 | 0x0010 | 0x0008 | 0x0004
class Py_buffer(Structure):
_fields_ = [
("buf", c_void_p),
("obj", c_void_p),
@ynkdir
ynkdir / winui3_webview2_environment_example.py
Last active September 20, 2025 05:11
Example to use WebView2 with CoreWebView2Environment.CreateWithOptionsAsync()
# Example to use WebView2 with CoreWebView2Environment.CreateWithOptionsAsync().
import asyncio
from win32more.Microsoft.UI.Xaml import Window
from win32more.Microsoft.UI.Xaml.Controls import WebView2
from win32more.Microsoft.Web.WebView2.Core import CoreWebView2Environment, CoreWebView2EnvironmentOptions
from win32more.Windows.Foundation import Uri
from win32more.appsdk.xaml import XamlApplication
@ynkdir
ynkdir / winui3_show_pil_image.py
Last active September 21, 2025 17:13
WinUI3 example for SoftwareBitmap
# How to show a PIL image in WinUI
import io
from PIL import Image
from win32more.Microsoft.UI.Xaml.Media.Imaging import BitmapImage, SoftwareBitmapSource
from win32more.Microsoft.Windows.Storage.Pickers import FileOpenPicker
from win32more.Windows.Graphics.Imaging import (
BitmapAlphaMode,
BitmapBufferAccessMode,
@ynkdir
ynkdir / winui3_thread_example.py
Created August 20, 2025 17:03
WinUI3 example for accessing UI component in worker thread.
# WinUI3 example for accessing UI component in subthread.
# UI component cannot be accessed in subthread.
# Use asyncio or DispatcherQueue to execute command in mainthread.
import asyncio
import threading
import time
from win32more.Microsoft.UI.Dispatching import DispatcherQueue
from win32more.Microsoft.UI.Xaml.Media import SolidColorBrush
@ynkdir
ynkdir / main.rs
Last active August 2, 2025 15:45
rust logging allocator
// https://doc.rust-lang.org/std/alloc/struct.System.html
use std::alloc::{GlobalAlloc, Layout, System};
use std::io::Write;
static HEX: [[u8; 1]; 16] = [
[0x30],
[0x31],
[0x32],
[0x33],
@ynkdir
ynkdir / shadowing.py
Created May 11, 2025 14:47
shadowing definition by decorator
# shadowing definition by decorator
import sys
class shadowing:
def __new__(cls, klass):
self = super().__new__(cls)
self._klass = klass
setattr(sys.modules[klass.__module__], klass.__name__, self)
return klass