CRTP in C♯: static polymorphism and friendship
Another therapy session for my Performance-Obsessive Disorder.
This site utilises several optional online services that might collect information about you. By continuing visiting this site (whether or not you dismiss this dialog), you acknowledge that you accept our privacy notice.
Another therapy session for my Performance-Obsessive Disorder.
POD (Performance-Obsessive Disorder) is an intended pun for Plain Old Data. This entry imagines how IEnumerable<T> of .NET could be upgraded for better performance, featuring duck typing with generics.
Some PowerPoint trick I used for preparing my Eurocrypt 2020 talk, plus a bonus.
Whitespace on its own does not entail a word boundary!
在博客中使用 BibTeX 的需求起源于一些需要引用文献的博文。例如之前的 NC¹ 属性加密 [KW19],那时候我是手工格式化参考文献的。当然,能自动化就不要手工去做,于是几个月前我开始了 BibTeX-TS——TypeScript 写的 BibTeX 解析器。现在设施已经足够完备,我可以把 alpha.bst 的实现近似翻译到 JavaScript 里,成为博客构建系统的一部分。
Microsoft Edge (Chromium) can pin websites to Taskbar in an undocumented way. I did some observation fun and this entry tells you how to programmatically pin/unpin Shortcuts to/from Taskbar (as of 1909). You should not abuse this knowledge.
最近有网友发现自己的 Windows 锁屏壁纸被修改成了百度云管家的广告。(一开始大家觉得是百度云管家乱搞,后来发现实际上是联想的 OEM 软件乱搞。)无论怎样,这说明一些软件用正常方式运行总让人不够放心,采取措施隔离一些 app 很有必要。一些网友提出可以给 app 准备一个专门的虚拟机,不过这有点大炮打蚊子了,其实可以用 Windows 的多用户和“以其他用户身份运行”解决。这个方法适用于很多 Windows 桌面 app。
You might expect PowerShell ConvertTo-Json cmdlet produce a JSON representation of a ‘POD’ that can be parsed (in particular, by ConvertFrom-Json cmdlet) into a POD object that equals to the previously serialised one. However, this is not true for many cases, the most surprising among which are double-precision numbers.
It is not the cmdlet that truncated the string. It’s the formatting. By the way, you can change the default if you want, and it’s all documented.
When you paste a URL of a YouTube video into OneNote, the cover image and the title are fetched by OneNote, the text of the link becomes the title, and an online video object (with the cover image) is inserted following the link. How can you disable this feature?
It doesn’t. Don’t invent a global conspiracy too early.
——原标题《Windows 文件关联略解》。上古时期一些乱七八糟的软件喜欢瞎搞文件关联,现在情况好多了。这篇博客简略讲述 Windows shell 的文件关联机制(不涉及 URL 协议关联)。这篇文章并不是 Microsoft 官方文档,一切请以官方文档为准。本篇的代码在 GitHub 上可见。
PowerShell 在众 shell 中最突出的特色就是面向对象;然而,世界上还有很多命名是专为字节流管道设计的(兼容性大坑)。PowerShell 对待字节流管道那是十分 nasty!我写的这个小工具可以在对象和字节流之间做完美的润滑。更新:Aloxaf 实现了 Linux 版本的 Use-RawPipeline,起名 Use-PosixPipeline。
It is widely spoken that the Equation Editor of Word (OneNote / Office) is inferior and harder to use than LaTeX. While this is true for a hardcore user, a lot of people spreading the word aren’t really understanding the thing and are just parroting others. I suspect that for a lot of them, the ability to efficiently typeset beautiful mathematical formulae is limited by knowledge and carefulness. People don’t seem to care enough to learn and correctly employ the tools at hand.
A commit to Ant Design, an enterprise-oriented open-source Web UI library by Ant Financial (蚂蚁金服), on 10 September 2018 buried an Easter egg for Christmas, which has caused a heck of havoc since Christmas. This entry also talks about not-so-obvious features in my blog.
Issue #6799 in PowerShell repository on GitHub raises the question why Previous Versions is opening previous versions of a directory in PowerShell, instead of File Explorer as expected. The reason is that PowerShell 6.1.0 (preview) installer creates a context menu to open the shell on any folder. However, it unfortunately names the verbs as open/runas, which is very dangerous since they are canonical and do not make much sense for a folder. Related is issue #7815, where shortcuts to a folder are opened in PowerShell.
日历是一个很棒的时间管理工具,作为学生,一个常见的需求是把课程表导入日历。这就引出了好几个需要考虑的问题。我经过几个学期的摸索,实现了一个对自己完全够用的日历管理工具。
Continuing ‘Hosting a preview handler in WPF, part 1: UI and file associations’, we will do the major COM interop in this entry. Many people have failed to host the handler correctly because of careless implementation, so look carefully! Also, we will demonstrate some broken preview handlers, including ‘Adobe PDF Preview Handler for Vista’, ‘Microsoft Word previewer’ and ‘Microsoft PowerPoint previewer’.
As a fanboy of Raymond Chen, I’m always intrigued by Windows Shell. After his three interesting examples of Reading a Contract From the Other Side, I decided to write one myself. Our victim is Preview Handlers and Shell Preview Host. Today’s entry will prepare UI and file association information retrieval for our little program.
交叉信息研究院的本科生操作系统课程的大作业很奇特,并不是 4 个 NachOS 作业,而是两次 NachOS、两次分布式数据库。最后一次大作业是要写一个 Bitcoin 挖矿程序,而且还有组间比赛,各个小组的矿机和客户端会一起运行一段时间,最终获得最高手续费的矿机会获胜。
Have you ever tried using UseNewEnvironment switch when invoking Start-Process cmdlet? Intuitively, turning it on makes the newly created process use the default environment instead of that of the parent process. However, its semantics is way more complicated, obscure and buggy than the intuition. TL; DR: You rarely want to use this switch.
The UAC Consent UI is rather involved in how it creates an elevated process, and it likes fooling around with process identifiers.
我觉得这是我参加的第 3 次 hackathon,并且是第 2 次 intensive hackathon。还是挺有意思的,记录,以飨。
两个小发现:Invoke-RestMethod 真的很好用;微软大法好!好吧,其实前一个也是“微软大法好”的一部分。
Continuing the last entry. I wrote a reducer of lambda terms (normal order, call-by-need).
I have heard about λ-calculus as a computational model for long, but never got a chance to have an even recreational look at it. Today’s entry simply records the creating of the parser.
When you open VS2015 Command Prompt from a newly installed instance of Visual Studio 2017 Community, the prompt fails to initialise the variables. Telling you to ‘make sure either Visual Studio or C++ Build SKU is installed’. Searching the Internet, this seems to be a known and persisting issue. Here I propose an elegant workaround for it.
Base conversion is the conversion between notations of number, and NOT the numbers themselves. I discuss a common mistake on methods of base conversion, and a common mistake in thinking about ‘base conversion’ in computer programs.
姚栋想要知道如何在 Windows 中使用命令解压缩 ZIP 文件夹。他表示如果要用 .NET Framework 提供的 API,则需要 4.5,但环境要求 4.0;如果用 PowerShell Expand-Archive 命令,则需要 5.1,但环境只允许 2.0;想用 cmd,但不知道怎么做。然而应该时刻记住:Windows 自带的 GUI 实际上经常是 COM 的图形版,在 COM 中寻找几乎总是可以找到你想要的图形操作的命令版本。
正在转战 C++ 写密码学代码,然后突然想温习一下多重继承、虚拟继承,熟知公有虚拟继承是 C++ 实现“接口”语义的成语(idiom,惯用法);思想游荡到了 C♯ 的世界,CLR 也支持接口,而且 C♯ 还有一个为人称道的显式接口实现(有一半私有虚拟继承的感觉),但是这里面隐藏了一个小“坑”……
This entry explores an interesting case of CRTP (curiously recurring template pattern) in C♯ that allows us to use operators. The other topic is elegant implementation of generic parameters that are (semantically) values instead of types.
A classic trick of backward references but painfully slow. And some comments on benchmarking JavaScript code.
A practical problem I encountered in 2016, which I insisted on implementing with pure CSS as long as it was possible. At first it was solved with mathematical logic tricks but later it turned out there was a much simpler solution.
And those APIs are specially designed for Edge (and modern IE) to enable Live Tile experience when the site is pinned to Start.
When Microsoft removes a useful thing.
One of the issues I encountered when I was at Jisuanke. Emulating is the point.
Something does not behave as desired on IE.
它的语义不等价于 std::function<TReturn(TArgs...)>。
Write some simple calls to multiple-window APIs.
Introducing multiple-window universal Windows apps.