米米的博客

做了一点微小的工作

Through the looking glass: Adding new hardware or overclocking what you've already got are among the leading ways to squeeze more performance out of your PC but in the earlier days of computing, all one had to do to give their PC a jolt was wiggle the mouse cursor around during an install.
添加新硬件或超频现有硬件是使 PC 获得更佳性能的主要方法。但在个人计算机的早期阶段,用户竟然还可以通过一个巧妙的办法来提升性能 —— 不停地晃动鼠标的光标。

Windows 95

I'm a self-professed fidgeter, especially at the computer. It's not uncommon to catch me moving the mouse all around with zero intent, even if I'm busy reading a story or watching a video.
我自认为是一个手抖的人,尤其是在电脑前。即使我在忙着用电脑读故事或看视频,你也会发现我在毫无目的地移动鼠标。

I chalk it up to the earlier days of computing when keeping the mouse active seemed to have a tangible benefit on system performance. Turns out, it wasn't just in our imagination.
我把它归结为在上古时期,保持鼠标活动似乎对系统性能有明显的好处。事实证明,这并不只是我们的想象。

According to a running thread over on Stack Exchange, moving the mouse cursor in Windows 95 did indeed speed up performance due to a flaw in the way the OS generates events and the fact that many applications are event driven.
根据 Stack Exchange 上一个正在热烈讨论的主题,在 Windows 95 中移动鼠标光标确实提升了性能,因为操作系统的事件生成方法存在缺陷,并且许多应用程序都是基于事件来驱动的。

As one user explains:
正如一位用户解释到:

Windows 95 applications often use asynchronous I/O, that is they ask for some file operation like a copy to be performed and then tell the OS that they can be put to sleep until that operation finishes. By sleeping they allow other applications to run, rather than wasting CPU time endlessly asking if the file operation has completed yet.
Windows 95 应用程序通常采用了异步 I/O,也就是说,在它们要求执行某些文件操作的时候(例如要执行的副本),会向操作系统表示其能够在操作完成之前转入休眠状态。通过这项休眠机制,其它应用程序将可以穿插空档来运行,而不是无休止地询问文件操作是否已经完成,从而浪费 CPU 时间。

For reasons that are not entirely clear, but probably due to performance problems on low end machines, Windows 95 tends to bundle up the messages about I/O completion and doesn't immediately wake up the application to service them. However, it does wake the application for user input, presumably to keep it feeling responsive, and when the application is awake it will handle any pending I/O messages too.
目前原因尚不完全清楚,但一个猜测是,这可能是为了解决低端计算机上的性能问题 ——Windows 95 倾向于捆绑关于 I/O 完成的消息,并且不会立即唤醒应用程序来为它们提供服务。不过,在用户输入时,操作系统会唤醒应用程序,这可能是为了让应用程序保持响应;而当应用程序处于唤醒状态时,它就能够处理任何挂起的 I/O 消息。

Thus wiggling the mouse causes the application to process I/O messages faster, and install quicker. The effect was quite pronounced; large applications that could take an hour to install could be reduced to 15 minutes with suitable mouse input.
换言之,晃动鼠标可以使应用程序更快地处理 I/O 消息,并加快安装速度。效果相当明显:配合合适的鼠标输入,原先可能需要一个小时安装的大型应用程序,耗时可以减少到 15 分钟。

As a youth, I'd keep my mouse cursor active as much as possible -- and especially during installs -- simply because I didn't want the screensaver to trigger and bog down system resources. Sure, I could have just set the timeout to longer on the screensaver, but that's beside the point. As it turns out, my actions were actually helpful, and not for the reason I thought.
在我年轻的时候,我尽可能地让鼠标光标处于活动状态 —— 尤其是在安装期间 —— 只是因为我不想让屏幕保护程序触发并阻塞系统资源。当然,我可以把屏保上的超时设置得更长一些,但这不是重点。事实证明,我的行为实际上是有帮助的 —— 即使这并不是我的初衷。


本文翻译自:Wiggling the mouse in Windows 95 made the operating system faster

什么是 Range 对象

Range 是指 html 文档中的区域,如用户用鼠标拖动选中的区域,如下图:

通过 Range 对象,可以获取用户选中的区域,或者指定选中区域,得到 Range 的起点和终点、修改或者复制里边的文本,甚至是 html。在富文本编辑器开发中,经常会使用到这些功能。

获取当前的选区

由于兼容性的问题,需要区分 IE 浏览器。

1
2
3
4
5
6
7
8
9
10
11
var selection, range;
if (window.getSelection) {
//现代浏览器
selection = window.getSelection();
} else if (document.selection) {
//IE
selection = document.selection.createRange();
}

//Range对象
range = selection.getRangeAt(0);

Range 对象的属性

属性描述
collapsed如果范围的开始点和结束点在文档的同一位置,则为 true,即范围是空的,或折叠的。
commonAncestorContainer范围的开始点和结束点的(即它们的祖先节点)、嵌套最深的 Document 节点。
endContainer包含范围的结束点的 Document 节点。
endOffsetendContainer 中的结束点位置。
startContainer包含范围的开始点的 Document 节点。
startOffsetstartContainer 中的开始点位置。

Range 对象的操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//选中区域的文字
var text = range.toString();

//选中区域的Element元素
var elem = range.commonAncestorContainer;
if (elem.nodeType != 1) {
elem = elem.parentNode;
}

//选中区域的html
var span = document.createElement('SPAN');
span.appendChild(range.cloneContents());

//选区是否为空
var isSelectionEmpty = false;
if (range.startContainer === range.endContainer) {
if (range.startOffset === range.endOffset) {
isSelectionEmpty = true;
}
}

参考文章:JS Range 对象的使用

Pro Controller 是任天堂为 Switch 适配的游戏手柄,于 2016 年 10 月 20 日与 Switch 一同亮相,并于 2017 年 1 月 25 日正式发布。除了在 Switch 上使用外,Pro Controller 还可以与 PC 配对或连接,进行 Steam 上的游戏 ——Steam 在 2018 年 5 月的客户端更新中增加了对 Pro Controller 的支持。

本文将介绍一个名为 x360ce 的工具,通过它可以将 Pro Controller 的操作映射为一个 Xbox 手柄。对于非 Steam 游戏,这比在 Steam 中设置手柄更加方便和友好。

Pro Controller 有两种与 PC 连接的方式:USB 有线连接和蓝牙连接。通过 USB 连接的 Pro Controller 只能被 steam 识别,而无论是 x360ce 还是 pygame 都无法正确读取数据。因此,要使用 x360ce,你的 PC 必须具有蓝牙功能。

下面将介绍操作步骤。

充电

通过 5V 电源适配器连接 USB Type-C 接口为 Pro Controller 充电,使其保持足够的电量。正如前面所说的,最好不要直接通过 PC 的 USB 接口连接 Pro Controller,以避免出现无法识别的情况。

蓝牙连接

长按 USB Type-C 接口旁的按键,使 Pro Controller 开机并进入蓝牙配对模式。在 PC 上通过蓝牙搜索并连接 Pro Controller。蓝牙配对完成后,就可以使用 x360ce 了。

安装 x360ce

下载最新版本的 x360ce,然后解压并运行。

点击「Add...」按钮,并勾选通过蓝牙连接的 Pro Controller。

完成后,点击「OK」回到之前的页面。

其它配置

将所有设置项按照前面图中的方式调整好即可。在「General」页面中,可以自行调整按键映射。在「Left Stick」和「Right Stick」中,可以调整灵敏度。完成设置后,需要点击「Save All」进行保存。

如果一切正常,系统会识别出 x360ce 虚拟的 Xbox 手柄,这样就可以愉快的进行游戏了!

以下操作中的快捷键在 Windows 下有效,macOS 可能需要用 Command 代替 Ctrl
原始素材尽量选择人物,最好不要全身。

笔者以下面这张梅西庆祝的照片为例。

调整对比度

打开素材,Ctrl+j 复制图层;选定新图层,Ctrl+m 打开曲线,调大对比度。

阅读全文 »
0%