Skip to content

Instantly share code, notes, and snippets.

View poychang's full-sized avatar
🌠
Magic Transforms the World

Poy Chang poychang

🌠
Magic Transforms the World
View GitHub Profile
@poychang
poychang / Note.md
Created May 10, 2024 09:17
Find Non-UTF8 Encoded Characters using Visual Studio Code (VS Code)

I ran into a problem with python where a file I wanted to read in and parse contained unexpected non-UTF-8 encoded characters. I am certain there are many ways to solve this problem, but capturing my quick and dirty appraoch below for posterity.

  1. Open the file and the Open Find
  2. In find, copy/paste the regex below:
^([\x00-\x7F]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|[\xEE-\xEF][\x80-\xBF]{2}|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$
  1. VS Code will highlight the lines MATCHING UTF encoded characters. So, you just have to skim the file looking for lines without highlighting.
@poychang
poychang / Install Android apps or apk files in Windows using Windows Subsystem for Android (No Emulator).md This Guide will show you how to install and run apk files or Android apps in any Edition of Windows 11 using Windows Subsystem for Android. WSA or Windows Subsystem for Android is a Tool that allows Windows to run Android Apps directly without using any emulator.

Install Android apps or apk files in Windows using Windows Subsystem for Android

WSA or Windows Subsystem for Android is a Tool that allows Windows to run Android Apps directly without using any emulator. The problem is Windows Subsystem for Android is currently only available through preview via the Beta Channel of the Windows Insider Program. But if you follow my guide, you don't have to be in Windows Insider Program to try it out. The only thing you need is Windows 11 installed and some patience.

Prerequisites:

  • Windows Subsystem for Android or WSA must be Installed.

Click here to view the guide that shows how to install Windows Subsystem for Android in any Edition of Windows 11 (including Windows 11 Home) non Inider or stable release.

How to Install Android Apps or apk files in Windows Subsystem for Android:

@poychang
poychang / Benchmark 效能測試樣板.linq
Created September 28, 2022 02:48
[LINQPad - Benchmark 效能測試樣板] 簡單驗證執行效能
#LINQPad optimize+
BenchmarkRunner.Run<BenchmarkJob>();
[SimpleJob(RunStrategy.ColdStart, targetCount: 10)]
[MemoryDiagnoser]
public class BenchmarkJob
{
[Benchmark]
public void Method1()
@poychang
poychang / youtube-dl.md
Created July 28, 2021 02:45 — forked from edgardo001/youtube-dl.md
Using youtube-dl to download courses from Pluralsight

Download courses from learning sites with youtube-dl

You can download whole courses from an array of tutorial sites with the CLI tool youtube-dl. In the example further down I'm using my Pluralsight account to get videos from a course at their site. Here is a list of all supported sites that you can download from with this tool

The flags you have to supply may vary depending on which site you make a request to.

You can get a free 3 month trial to Pluralsight by signing up for free to Visual Studio Dev Essentials

Installation

@poychang
poychang / ThenExtension.cs
Last active September 28, 2022 02:47
[LINQ 擴充 - 然後呢] "然後呢"擴充方法 #C# #dotnet
public static class ThenExtension
{
/// <summary>
/// "然後呢"擴充方法
/// </summary>
/// <typeparam name="T">原本的物件型別</typeparam>
/// <param name="instance">原本的物件</param>
/// <param name="fn">然後你要執行什麼,並回傳變更後的物件</param>
/// <returns>原本的物件,可能會變更原本物件的屬性值</returns>
public static T Then<T>(this T instance, Func<T, T> fn) => fn(instance);
@poychang
poychang / main.cs
Created March 2, 2021 01:17
[Self Instance 的寫法] 簡單的 Singleton 寫法 #dotnet #c
void Main()
{
var instance1 = SampleService.Instance;
var instance2 = SampleService.Instance;
Console.WriteLine(instance1.WhoAmI().Equals(instance2.WhoAmI()) ? "It's the same instance." : "It's NOT the same instance.");
Console.WriteLine();
var instanceWithCtor1 = SampleServiceWithCtor.SelfInstance("Poy Chang");
var instanceWithCtor2 = SampleServiceWithCtor.SelfInstance("Poy Chang");
@poychang
poychang / WmiSearcher.cs
Created June 15, 2020 15:31
[WMI Searcher] 返回容易存取的物件
void Main()
{
GetComponent("Win32_PhysicalMemory")
.Select(p => p.ToObject<Win32_PhysicalMemory>())
.ToList()
.ForEach(item => Console.WriteLine(item.Manufacturer));
}
/// <summary>
/// 取得指定硬體設備類別的所有屬性資料
@poychang
poychang / README.md
Created March 25, 2020 10:03 — forked from magnetikonline/README.md
PowerShell Import-Module with .ps1 quirk.

PowerShell Import-Module with .ps1 quirk

Well, not so much a quirk - but an interesting anti-pattern I found in some (poor quality) PowerShell. Documenting the "how and why" so I can refer to it again if needed!

Example

We have two files callme.ps1 and functions.ps1:

functions.ps1:

@poychang
poychang / rangeGenerator.js
Created March 4, 2020 01:25
[比較 Array 和 Generator 的作法]
// 搭配 Quokka.js 來測試會比較方便看
function* rangeGenerator(start, end) {
for (let i = start; i < end; i++) yield i;
}
function range(start, end) {
return Array.from({ length: end - start }, (_, i) => i + start);
}
@poychang
poychang / github-markdown.css
Created December 20, 2019 06:18
Markdown to HTML style sample
@font-face {
font-family: octicons-link;
src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAZwABAAAAAACFQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABEU0lHAAAGaAAAAAgAAAAIAAAAAUdTVUIAAAZcAAAACgAAAAoAAQAAT1MvMgAAAyQAAABJAAAAYFYEU3RjbWFwAAADcAAAAEUAAACAAJThvmN2dCAAAATkAAAABAAAAAQAAAAAZnBnbQAAA7gAAACyAAABCUM+8IhnYXNwAAAGTAAAABAAAAAQABoAI2dseWYAAAFsAAABPAAAAZwcEq9taGVhZAAAAsgAAAA0AAAANgh4a91oaGVhAAADCAAAABoAAAAkCA8DRGhtdHgAAAL8AAAADAAAAAwGAACfbG9jYQAAAsAAAAAIAAAACABiATBtYXhwAAACqAAAABgAAAAgAA8ASm5hbWUAAAToAAABQgAAAlXu73sOcG9zdAAABiwAAAAeAAAAME3QpOBwcmVwAAAEbAAAAHYAAAB/aFGpk3jaTY6xa8JAGMW/O62BDi0tJLYQincXEypYIiGJjSgHniQ6umTsUEyLm5BV6NDBP8Tpts6F0v+k/0an2i+itHDw3v2+9+DBKTzsJNnWJNTgHEy4BgG3EMI9DCEDOGEXzDADU5hBKMIgNPZqoD3SilVaXZCER3/I7AtxEJLtzzuZfI+VVkprxTlXShWKb3TBecG11rwoNlmmn1P2WYcJczl32etSpKnziC7lQyWe1smVPy/Lt7Kc+0vWY/gAgIIEqAN9we0pwKXreiMasxvabDQMM4riO+qxM2ogwDGOZTXxwxDiycQIcoYFBLj5K3EIaSctAq2kTYiw+ymhce7vwM9jSqO8JyVd5RH9gyTt2+J/yUmYlIR0s04n6+7Vm1ozezUeLEaUjhaDSuXHwVRgvLJn1tQ7xiuVv/ocTRF42mNgZGBgYGbwZOBiAAFGJBIMAA