Skip to content

Instantly share code, notes, and snippets.

@GeeLaw
GeeLaw / dispornt.cpp
Created March 23, 2024 03:28
Compute the display orientation of the current thread using plain old Win32 API.
/* SPDX-License-Identifier: MIT
Copyright (c) 2024 by Ji Luo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@GeeLaw
GeeLaw / save-douban-ebook.md
Last active March 16, 2024 07:10
从豆瓣阅读网页版保存用户已经可以阅读的电子书
@GeeLaw
GeeLaw / pokemon.cpp
Last active April 9, 2024 12:12
通过攻击抗性决定敌方宝可梦的属性组合 / determining type combo of an unknown enemy pokémon from type-based prompts against attacks
/*
Copyright 2024 by Ji Luo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@GeeLaw
GeeLaw / f_2_256.cc
Last active January 22, 2024 04:19
An implementation of the finite field of order 2^256.
/*
An implementation of the finite field of order 2^256.
The MIT License (MIT)
Copyright (c) 2024 Ji Luo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@GeeLaw
GeeLaw / puzzle.cs
Created September 1, 2023 23:20
`int[]` is `int[*]`, and the constructor of `int[*]` could create an instance of type `int[]`.
/* https://twitter.com/geelaw95/status/1697748857541800366
Copyright (c) 2023 Ji Luo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@GeeLaw
GeeLaw / CopyLocalLink.vba
Created May 9, 2021 16:01
Outlook local links
@GeeLaw
GeeLaw / onedrive-bug-report.md
Created April 29, 2021 10:41
Bug in Cloud Filer / Placeholder / Reparse Point Disguising / OneDrive sync engine

Bug in Cloud Filer / Placeholder / Reparse Point Disguising / OneDrive sync engine

Starting from an unknown version of Windows 10, programs can no longer access dehydrated (online-only, placeholder) files with CreateFile(Ex) normally.

Consider the following excerpt:

// By default (if the program does not have a manifest, so it runs in Windows Vista mode),
// RtlQueryProcessPlaceholderCompatibilityMode returns PHCM_DISGUISE_PLACEHOLDER, and
// RtlQueryThreadPlaceholderCompatibilityMode returns PHCM_APPLICATION_DEFAULT.
@GeeLaw
GeeLaw / CreateAppointmentFromMessage.vb
Created October 16, 2020 11:13
Outlook macro: Create appointment from e-mail.
Option Explicit
Sub CreateAppointmentFromMessage()
Dim activeWin As Object
Dim targetItem As Object
Dim targetMsg As MailItem
Dim targetFolder As Folder
Dim newAppointment As AppointmentItem
Dim msgInspector As Inspector
@GeeLaw
GeeLaw / CrtpBenchmark.cs
Created October 4, 2020 15:35
CRTP benchmark (C#)
/**** Benchmarking CRTP without virtual dispatch in C#.
See https://geelaw.blog/entries/csharp-crtp-static-polymorphism-friendship/
Results on my Surface Book 2:
| milliseconds | struct, non-virtual | struct, virtual | virtual |
| :----------: | :-----------------: | :-------------: | :-----: |
| x86 Core 3.1 | 1065 | 1405 | 1431 |
| x64 Core 3.1 | 1015 | 1371 | 1418 |
| x86 Fx 4.7.2 | 1160 | 1501 | 1490 |
@GeeLaw
GeeLaw / Program.cs
Created August 11, 2020 12:10
`IEnumerable<T, TEnumerator>` for more precise type propagation in C♯ generics.
/* See https://geelaw.blog/entries/csharp-generics-duck-typing/ for the context.
Copyright (c) 2020 by Gee Law
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the “Software”),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions: