跳至主要内容

博文

目前显示的是 2018的博文

NWL - 安全桩

火车站附近最近在施工,是要为入口处安放防撞的安全桩。 和同事聊起来,学到了这个新词 Bollard。 > A bollard is a sturdy, short, vertical post. > > The term originally referred to a post on a ship or quay used > principally for mooring boats, but is now also used to refer to > posts installed to control road traffic and posts designed to > prevent ram raiding and car ramming attacks. Ramming 就是以自身撞击的意思。 > In warfare, ramming refers to hitting a target by running oneself into the target. 另外,既然也提到了 quay (码头)那么再复习一下它的“同义词”: > Quay and wharf are originally different in usage only really. A wharf is for the commercial unloading and loading of ships and is (usually) private property belonging to a shipping company. A quay is for smaller ships or boats and is available for general use, these are frequently owned and operated by the local governments/councils for the benefit of local fishermen originally. Passenger ships would usually dock at quays, cargo ships at wharves. > A pier is a man-made construc...

解决thinkpad e450 windows 10重灌后的启动问题

为LD的thinkpad e450更换了SSD 500GB,之后重装windows 10 home。利用微软的Media Creation Tool灌了一支安装U盘,不过一开始怎么都没法找到这个U盘。 上网查了之后得知这是由于BIOS里设定了Secure Boot和UEFI mode only,于是禁用,遂成功找到U盘,并顺利安装了系统。 不过发现Legacy Mode下启动的速度还是较慢,于是想要恢复到UEFI和Secure Boot,没料到这么一改居然又进不了系统了!!! 继续学习,较老的帖子是为了从Win8降级到Win7,他们本来就不要用UEFI。而有的帖子建议用PE重建启动分区,感觉还是很麻烦。 好在,最后[这个帖子的回答](https://www.dell.com/community/Inspiron/Used-Legacy-Boot-can-t-get-UEFI-w-Sec-Boot-back/m-p/5807869#M8113)让我发现微软非常非常非常好心的在win10内建了一个工具 [mbr2gpt](https://docs.microsoft.com/en-us/windows/deployment/mbr-to-gpt),只要进入windows 10系统就可以直接帮助切割一个EFI System Partition,所有的文件系统基本上都不会受到影响。 这篇回答非常精彩,摘抄如下: > Windows installs itself differently depending on whether it will be booted in Legacy or UEFI. The way that you booted the Windows installation media itself depends on how the OS that gets installed is set up. So it sounds like you booted your install media in Legacy mode, in which case Windows set up your disk in MBR partition layout intended for Legacy booting. You can...

解决 Windows 10 播放视频有声音但是黑屏的问题

上周在PC上打开一个mp4文件后发现Windows 10自带的播放器(程序名为“电影和电视”)居然只能出声,播放的是黑屏。当时没在意,换了手机来看。 今天又一次遇到了同样的问题,换了VLC播放还是如此,看来不是单个程序的问题。试着重装了VLC也没有用,可以排除和解码器有关的问题。 难道是微软近期的更新又出了幺蛾子?万能的谷歌再一次大发神威,在 answers.microsoft.com 上找到了一枚支持贴——[【windows 10播放本地视频只有声音没有影像】](https://answers.microsoft.com/zh-hans/windows/forum/windows_10-start/windows/06e3bad9-8238-4300-b6b9-997a90a7c373) > 这似乎是个共性的问题。请问您是什么样的设备配置?是否是AMD显卡的设备?是否是双显卡设备? > > 若是AMD显卡设备,请参考以下步骤: > > 1. 右击计算机桌面任意空白位置,选择“显示卡属性”选项,打开AMD显卡控制台; > 2. 选择“首选项”按钮,将“视图模式”改为“高级视图”; > 3. “视频”选项卡中取消勾选“覆盖程序设置”的选项,然后查看问题是否得到解决。 > 4. 若无效,可以尝试禁用显卡驱动。 > > 若不是AMD显卡的设备,一般不会出现该情况,建议您检查您的驱动程序版本,驱动程序版本并非最新的就是最好的,您需要下载适合您系统的驱动程序。 > > 若是双显卡设备,请禁用独立显卡。 几乎全中!立刻打开 AMD Catalyst Control Center,虽然没有找到上述提到的“覆盖程序设置”,不过捣鼓了一下重启后还是解决了。

Auto format files based on type in VIM

It would be really convenient to utilise the editor to auto-format some lengthy lines, e.g. a super long SQL retrieved from logging output; or a wrapped JSON literal captured in your browser. Luckily it's easy to achieve this in VIM - Firat, you'll need to install a few modules using `pip`, including `sqlparse` and `json.tool`. And then in the `filetype.vim` (or your own `vimrc`), include below commands: autocmd FileType xml setlocal equalprg=xmllint\ --format\ --recover\ -\ 5>/dev/null autocmd FileType json setlocal equalprg=python\ -m\ json.tool autocmd FileType sql setlocal equalprg=python\ -m\ sqlparse\ -a\ -s\ -

阅读笔记:编写测试是为了增强信心

最近在读一本有年头的书—— [Test-Driven Development By Example](https://www.amazon.com/Test-Driven-Development-Kent-Beck/dp/0321146530)。 Chapter 4 里展示了在编写测试代码的过程中,可以利用被测对象的functionality (例子中是为对象新增的 `equals` 方法)来改进代码,取代原有测试中直接访问 被测对象的field的方式。由此可以将那个 field 改为 `private`。 不难看出,这里引入了一层“间接”性。Kent 很坦率的指出: > Notice that we have opened ourselves up to a risk. If the test > for equality fails to accurately check the equality is working, > then the test for multiplication could also fail ... 既然多了一层依赖,代码就不再直接检测原有的 equality,这究竟是不是一件坏事呢? > This is a risk that we actively manage in TDD. > We aren't striving for perfection. By saying everyting two ways - > both as code and as tests - we hope to reduce our defects enough to > move forward with confidence. 所以,TDD本身不是为了盲目的追求测试覆盖率,它的本质是让开发者通过编写充分 的测试来对自己的代码获得信心! > From time to time our reasonging will fail us and a defect will slip > through. When that happens, we learn our lesson about the test we > should have written and ...

Learning SpaceVim

最近一直试着用SpaceVim,在Mac上取消了自定义的vimrc,直接用 init.toml 作为配置文件。 体验下来感觉SpaceVim的配置是更高一层的,用户可以指定需要的 layer,不过有一些低一层的配置暂时还不晓得如何移植过去? ``` [options] realtime_leader_guide = 1 enable_tabline_filetype_icon = 1 enable_statusline_display_mode = 0 statusline_separator = 'slant' enable_os_fileformat_icon = 1 buffer_index_type = 1 colorscheme = 'koehler' enable_vimfiler_welcome = 1 enable_debug = 1 guifont = 'Hack\ Regular\ Nerd\ Font\ Complete:h14' bootstrap_before = "spcvm#autoformat" [[layers]] name = 'ctrlp' [[layers]] name = 'git' [[layers]] name = 'lang' [[layers]] name = 'lang#javascript' on_ft = ['js', 'javascript'] [[layers]] name = 'lang#typescript' on_ft = 'ts' [[layers]] name = 'lang#json' on_ft = ['json', 'jsonp'] [[layers]] name = 'lang#java' o...

Windows 10 卓越性能模式

Windows 10 升级到 version 1803 版本之后,可以打开一个隐藏的电源计划,也就是传说中的“卓越性能”模式。 具体操作是以管理员身份打开 PowerShell 窗口,输入以下指令: powercfg -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61 具体是哪里可以体现极限,媒体的报道也语焉不详: > “极限性能”模式是专门为高端台式系统打造的。 > 如果你想在电池供电的笔记本平台上使用,显然是无法享受到其所宣称的最佳体验的。 不过好歹俺的台式机N年前也算是还凑合的 [Intel i7-4790K](https://ark.intel.com/products/80807/Intel-Core-i7-4790K-Processor-8M-Cache-up-to-4_40-GHz),虽然生命周期已经 discontinued 了,不过期望多少可以压榨一点油水吧?

Windows 10 Version 1709 的累积更新失败

笔记本的Windows 10自动更新要求重启,但是重启之后提示说更新安装失败。再次尝试,重启后还是如此,于是陷入了这个魔咒无法脱身。 后来查了Google,发现都不如Windows自带的链接管用,根据KB的号码找文档,可以下载到相应的独立更新安装包。 另外还参考了一个[微软的官方客服回答](https://answers.microsoft.com/en-us/windows/forum/windows_10-windows_install/getting-error-0x80070bc2-doing-cumulative-update/24e80681-eb22-4439-8677-638fce437186?page=7)执行了如下cmd操作: ``` SC config wuauserv start=auto SC config bits start=auto SC config cryptsvc start=auto SC config trustedinstaller start=auto ```

Dev's Ranting - Hibernate batch processing

Recently I have been working on a performance issue of a small application. It utilizes Hibernate to delete a lot of entities from database. Unfortunately the application died throwing a `OutOfMemoryError`. After discussing with my colleagues and reading some posts about how Hibernate works in batch mode, it appears to me that Hibernate's batch mode (`order_inserts` and/or `order_updates`) may played some role in this issue. Ref: * [Why is Hibernate batching / order_inserts / order_updates disabled by default](https://stackoverflow.com/questions/27755461/why-is-hibernate-batching-order-inserts-order-updates-disabled-by-default) * [Hibernate Batch Processing - Why you may not be using it. (Even if you think you are](https://abramsm.wordpress.com/2008/04/23/hibernate-batch-processing-why-you-may-not-be-using-it-even-if-you-think-you-are/)

PowerShell Exercises - Rename file names in batch

以前用TotalCommander来做batch rename的,GUI下输入pattern挺方便的。现在的PC上没有安装,于是要靠命令行了。 好在PowerShell的pipe也不算太糟糕: Get-ChildItem directory | Rename-Item -NewName { $_.Name -replace '^filename_+','' } 如果有多个 patterns 需要替换可以使用多组 `-replace` 表达式组合。

组合使用 you-get 和 ffmpeg

最近对 `you-get` 这个神奇的下载器挺感兴趣的,用它在油管上下了一些MV,顺手下了另一个大名鼎鼎的工具 `ffmpeg` 将歌曲转换为 MP3。 > you-get -o D:\DOWNLOAD http://some-url 假定文件保存为 `'some-mv.mp4'`, > ffmpeg -i D:\DOWNLOAD\some-mv.mp4 -vn -ab 256k some.MP3。 有的时候如果需要截取部分来转换,可以加上两个参数 `-ss` 和 `-to`: > ffmpeg -i D:\DOWNLOAD\some-mv.mp4 -vn -ab 256k -ss 00:03:12 -to 04:15:43 sub-convert.mp3 简单的参数解释: + `-vn` 不要视频,也就是转换为音频格式 + `-ab bitrate` 指定音频的比特率 + `-ss time_offset` 指定从哪个时间点开始 + `-to time_stop` 指定停止的时间点 当然 `ffmpeg` 提供的参数远不止这些,[这里](http://blog.topspeedsnail.com/archives/1699)有一片不错的使用介绍可以参考。

From markdown to PDF using Pandoc

花了点儿时间玩 Pandoc,将一些 Markdown 文档转换为 PDF 文档。 首先参考[官方文档](https://pandoc.org/installing.html)在 Mac OS 上安装了 Pandoc: > You can install pandoc using homebrew: `brew install pandoc`. > > There is a package installer at pandoc’s download page. If you later want to uninstall the package, you can do so by downloading this script and running it with perl uninstall-pandoc.pl. > > We also provide a zip file containing the binaries and man pages, for those who prefer not to use the installer. Simply unzip the file and move the binaries and man pages to whatever directory you like. > > For PDF output, you’ll also need LaTeX. Because a full MacTeX installation takes more than a gigabyte of disk space, we recommend installing BasicTeX (64M) and using the tlmgr tool to install additional packages as needed. If you get errors warning of fonts not found, try `tlmgr install collection-fontsrecommended` 安装了 BasicTex 之后一直在 Apps 里寻找 `LaTex` 或是 `BasicTex` 这样的应用,但是一无所获(?!) 后来跑到 MacTex...

Code to Graph

花了点儿时间寻找适合 code 转换为 graph 的工具,发现了 pandoc 和 Graphviz。 [Graphviz](https://graphviz.gitlab.io/documentation/) 貌似比较有趣,下载了一个Windows的版本,安装之后在 Win10 上没有任何的图标添加,要自己到安装目录下找到 `bin/gvedit.exe` 打开。 另外找到了一篇[很详细的攻略](http://blog.jobbole.com/94472/)来学习如何使用 Dot 语言来绘图。

解决由ATI显卡驱动导致的爆音

一直以来电脑有个问题,在开始播放音乐或是看片的时候,音箱里首先一下爆音。如果播放的音频时间很短,那么干脆就听不见——甚至连Windows的开机声音也没有。 花了点儿功夫求助Google,初步得到的结论是由于PC上的ATI显卡驱动和主板的Realtek音频驱动有冲突导致的。后来找到了 [Realtek 官网所提供的 High Definition Audio Codecs](http://www.realtek.com.tw/downloads/downloadsCheck.aspx?langid=1&pfid=24&level=4&conn=3&downtypeid=3),其中有一个专门为 ATI 设备编写的驱动名为『ATI HDMI Audio Device』,版本是R2.70,虽然最后的更新时间是五年前(2012/6/2)不过这不重要,果断下载安装。 重启后一切搞定~

Running Kubernutes in Windows 10

试着在 Windows 10 PC 上玩 docker 和 Kubernetes。作为容器管理平台,Kubernetes 可以被安装并运行在不同类型的环境下,包括开发者的笔记本电脑,或是云服务商的VM,甚至是一组裸机上…… 参考官方文档 [Picking the Right Solution](https://kubernetes.io/docs/setup/pick-right-solution/) 找到了适合创建单机单节点 Kubernetes Cluster 的 [Minikube](https://kubernetes.io/docs/getting-started-guides/minikube/#minikube-features)。 Minikube 提供的特性包括: * DNS * NodePorts * ConfigMaps and Secrets * Dashboards * Container Runtime: Docker, rkt and CRI-O * and etc. 安装 Minucube 的步骤看起来也挺简单的,先要 PC 的 BIOS 支持 VT-x 或是 AMD-v 虚拟技术,这年头只要不是太老的 PC 都行。接着需要在 OS 里装一个 Hypervisor,对 Windows 而言常见的就是 VirtualBox 或者 Hyper-V。 之前为了安装 Docker for Windows 卸载了 VirtualBox 改用 Hyper-V,因为 docker 的文档 [Machine Driver](https://docs.docker.com/machine/drivers/hyper-v/) 里明说了: > Hyper-V must be enabled on your desktop system. Docker for Windows automatically enables it upon install 谁让人家是微软的亲儿子捏? 接着要安装 `kubectl` 这是 Kubernetes 的 CLI (命令行工具),在 Windows 10 里可以利用 Chocolatey 包管理器来[代为安装](https://kubernetes.io/docs/tasks/tools/inst...