prepare-det
Today I start to prepare Duolingo English Test. I made honey sweet potato chips for the children today, and the children loved it.
Today I start to prepare Duolingo English Test. I made honey sweet potato chips for the children today, and the children loved it.
Vim is a powerful and versatile text editor that offers a wide range of features and customization options. In this article, we will explore some useful tips and techniques from the book “Modern Vim” to help you become more efficient and productive in your Vim editing.
Vim has a unique set of keyboard shortcuts and commands that can enhance your editing experience. Here are some key concepts and shortcuts to keep in mind:
<C-p>
represents pressing the Control key followed by the letter “p.”
Operators are commands used to perform actions on text. Some common operators include:
1 | `c` for change |
The Meta
key:
To get the most out of Vim, it’s recommended to use Neovim and the neovim-remote tool developed by Marco Hinz. This tool allows remote control of Neovim processes.
Plugins are a great way to extend Vim’s functionality. Here are some insights on managing plugins:
Understanding Scripts, Plugins, and Packages:
:source {path}
command, where {path}
is the location of the script.vimrc
file is one of the first scripts to be loaded, making it an ideal place to configure your startup settings.runtimepath
to include plugins was not convenient. However, you can now use the :set runtimepath+=$VIMCONFIG/arbitrary/demo-plugin
command to add a plugin to the runtimepath
.<C-]>
will jump to the specified anchor in Vim’s documentation, and you can use <C-o>
to quickly jump back to the previous location. These commands allow you to navigate Vim’s documentation similar to interacting with a web page.:helptags
once. Vim will then use the generated tags file to find the documentation for that plugin.Installing Plugins to Your Package:
start
directory while Vim is running, you won’t be able to use it immediately. Restarting Vim will add the new plugin to the runtimepath
and make it available.:helptags ALL
command (:help :helptags
).:silent helptags ALL
.:packadd
command to activate a plugin (e.g., :packadd vim-scriptease
).Managing Plugins with minpac:
:call minpac#update()
can be cumbersome. You can create custom commands to make it more convenient:command! PackUpdate call minpac#update()
command! PackClean call minpac#clean()
Efficiently opening and navigating files is crucial for an effective editing workflow. Let’s explore two techniques:
Finding Files Using Fuzzy Path Matching:
<C-x>
, <C-v>
, or <C-t>
to open a file in a horizontal split, vertical split, or new tab, respectively.rg --files
command (Ripgrep) filters out files ignored by Git, Mercurial, and Subversion repositories.Finding Files Semantically:
Open files in separate windows using the -O
flag. For example:
vim -O file1.txt file2.txt
You can define file-to-type mappings in a .projections.json
file. For instance:
"app/models/*.js": { "type": "model" }
Vim provides navigation commands specific to file types, such as:
:Etype
- Opens the specified type in the current window:Stype
- Opens the specified type in a horizontal split:Vtype
- Opens the specified type in a vertical split:Ttype
- Opens the specified type in a new tabpage1 |
|
Restarting Terminal Processes When Resuming a Session:
:file {name}
command (:help :file_f
). Activate the window containing the terminal buffer running the web server and run::file term://PORT=3001 npm run server
Customizing Vim’s behavior can greatly enhance your editing experience. Here’s a technique to respond to events using autocommands:
BufReadPost
command (:h BufReadPost
) after reading a file into a buffer. If the file path matches the pattern defined in our autocommand, Vim executes the specified {command}
. Since we use a wildcard *
in this example, the autocommand applies to all buffers.FileType
event (:h FileType
).autocmd BufWritePre /tmp/* setlocal noundofile
User
event with the pattern ProjectionistActivate
. The User
event doesn’t trigger automatically, but you can trigger such events yourself::doautocmd User ProjectionistActivate
In this article, we’ve explored various tips and techniques from “Modern Vim” to help you enhance your Vim editing skills. By incorporating these techniques into your workflow, you can become a more efficient and productive Vim user.
Keystone是一个强大的Node.js内容管理系统,它是建立在Express和Mongoose ODM上的Web App框架。Mongoose ODM是面向文档映射,为那些存储到MongoDB数据库中文档,其提供了面向基于模式的解决方案来为数据和关系建模。Keystone扩展了Mongoose基于模式模型。Keystone列表利用智能字段类型帮助你构建漂亮的Admin界面。
Keystone的目标是让你更容易的构建复杂网站和应用,而不限制你自定义功能。你可以引入你自己的视图引擎,设计你想要的路由,并且修改你的数据结构来适应你的需求。
确保你安装好了Node.js JavaScript运行环境。Keystone 4主要是在Node 6上进行测试,但是应当是和最新正式版Node是兼容的。我们推荐使用Node LTS(长期支持)版本,因为更长的支持周期和稳定性。(译者注:LTS 版本更注重稳定性和扩展支持,通常将支持 30 个月。)
你也要可以访问一个MongoDB数据库,不管是安装在本地还是部署在远程服务器上。Keystone 4兼容最新的MongoDB正式版。
你需要有一定的JavaScript、Node.js和npm的知识来使用Keystone。了解数据库概念和MongoDB则更有帮助。
如果你想要在本地快速运行一个项目,我们推荐你从Keystone Yeoman生成器开始。Keystone Yeoman生成器提供了一个提示命令行来帮助你生成完整的项目,可以通过npm来定制一些特性如基础的博客,反馈表单,相册功能。
如果你更喜欢从脚手架编写你的代码,产看我们第四部分的设置教程。这个教程让你从核心的文件和设置来开始Keystone。
如果你想要学习更多的Keystone设置选项,请查阅我们的文档。数据库配置是一个好的起点,同样Keystone通用设置选项也是不错的选择。
给定一组单词,返回所有字母都在同一行美国键盘上的单词。
例子:
Input: ["Hello", "Alaska", "Dad", "Peace"]
Output: ["Alaska", "Dad"]
注意:
解决思路有两种。最简单的方法是利用正则表达式来判断字母是否满足正则表达式,如果满足则表示单词有效。这里面有几点需要注意的。
1 | class Solution { |
第二种方法就麻烦一点了。
1 | class Solution { |
给定一个正数,输出它的“补数”。求的方法是把二进制位置的数进行取反。
注意:
- 给定的正数在32位内
- 正数前面没有补0。比如2(B10),在它的前面没有0。
例子1:
输入: 5
输出: 2
解释: 5的二进制数是101 (前面不补充0), 它的补数是010。所以输出是2。
例子2:
输入: 1
输出: 0
解释: 1的二进制是1 (前面不补充0), 它的补数是0。因此输出是0。
假设输入数为input, 输出为output, 设mask的二进制位数与input相等,且每一位都为1。
这里求input有两种方法。这里你可以用上面的例子数据代进去验证一下。
所以这个问题的关键是如何得到mask。
还有第三种思路是这样的。每次将input分别与其对应二进制位为1的数进行异或操作,就能得到output。
1 | class Solution(object): |
mask
方法一:1 | var flipMask: UInt32 = ~0 |
将全是’1’的UInt32
数不断的左移,直到(numUInt32 & flipMask) == 0
停止,然后再对flipMask
取反就能得到要求的mask
。
mask
方法二:1 | int mask = 0; |
从右往左不断的增加1的位数,直到mask >= num
。
mask
方法三:1 | int mask = num; |
每次与右移后的值进行与操作,移动的位数每次能扩大2倍。这样就能保证mask的所有二进制位都是1。
mask
方法四:1 | mask = ((2<<int(math.log(num, 2)))-1) |
利用数学函数能得到input的位数(int(math.log(num, 2))+1
), 这样进1位减去1就得到了mask
值。
给定两个数字,求这两个数的二进制数相应位不同的总数。
注意:
$0 \leq x, y < 2^{31}$
例子:
输入: x=1, y=4
输出: 2
解释:
1 (0 0 0 1)
4 (0 1 0 0)
^ ^
上面箭头指的位置相应两个数字的二进制位不一样,一共有2处。
##解法1:
1 | // javascript |
首先通过异或操作得到一个值xor。
在循环里面判断有几个不一样的位置。
从最后一位开始判断,直到所有位置判断完成。
##解法2:
1 | // javascript |
第一步同解法一。
第二步转换成操作字符串的操作。
删除’0’,随后判断字符串的长度,即不同位置数。
##解法3:
1 | //javascript |
其实这个问题可以简化成找出二进制数中有几个‘1’。比如异或结果是‘1010’,其中有2个‘1’表示hamming distance是2。
这段代码while循环可能一眼看上去发现自己懵逼了。其实xor &= xor-1;
这个操作是移除一个’1‘。有几个就是移除几次。如果还懵逼,可以多调试几次。
给定一组数和一个目标值,求出两个加数的位置。
比如:
1 | nums = [2, 7, 11, 15], target = 9 |
注意返回的位置是基于0的
##方法一 O(n^2)
1 | /** |
##方法二 O(n)
1 | /** |
##总结
方法二巧妙利用hashMap取值的时间是固定的这一特点。把复杂度从O(n^2) 降到了O(n)。
从学习iOS开发就开始接触到MVC的开发模式了。随着越来越注重用户体验以及业务越来越复杂。ViewController也越来越臃肿,同时我们的工作量也越来越大。在ViewController中混杂着业务逻辑与UI处理的逻辑。完整的测试ViewController既要对UI进行测试也需要对业务逻辑进行测试。测试起来比较麻烦。
物极必反 器满则倾
接下来进入正题,看看MVVM设计模式是如何解决这些问题的。
MVVM = Model + View + ViewModel
看上去和MVC差不多,就是把ViewController替换成了ViewModel。如果是这样的话,MVVM压根就没有存在的必要了。所以并不是进行了简单的替换。MVVM由3部分组成:Model , View , ViewModel。
##iOS中的MVVM
然并卵iOS中我们没有办法绕过UIViewController。诸如UITabController, UINavigationController是非常非常常用的。没有这些容器,我们写界面时的情景简直不敢想象。IB与UIViewController的结合比较紧密。如果你通过IB来画界面的话,更离不开UIViewController。那么iOS中的MVVM是什么样的?
Model,View,ViewModel的职责都没有改变。iOS的MVVM开发模式中ViewController只做与视图有关的操作,以及连接View与ViewModel的胶水代码。也就是说View部分其实是由原本的View+部分ViewController组成。
一旦我们这样组织代码,首先进行业务逻辑测试的时候我们只需要测试ViewModel就可以。测试UI只需要测试View+ViewController。对于UI的自动化测试我一直没有找到什么特别好的办法,可能主要靠手工和一些第三方的测试平台吧。其次我们在开发过程中可以进行并行开发了,即可以同时开发界面和业务逻辑。即使你是一个人开发App,那么每一次只做一件事情同样会让你的头脑更清楚。
##胶水代码
iOS中没有胶水代码的MVVM是不完整的
胶水代码都做了哪些事情?
在ReactiveCocoa出来之前,胶水代码很难写的很优雅。这也是为什么以前iOS中MVVM并不怎么火的原因。关于ReactiveCocoa的学习与使用本文不会涉及。如果有需要可以自行搜索学习。它是响应式开发的利器。
iOS的MVVM开发模式不能没有”ReactiveCocoa”
没有胶水代码,你不能将业务逻辑从ViewController中抽离。
也谈谈MVVM(二)将会进行实战演练。结合一个简单的Demo进行讲解MVVM开发模式。敬请期待!另外欢迎大家能和我一起讨论交流,一起进步。
未完待续…
我们公司在南京招聘iOS的时候,人真难找啊。而我也一直有想开设一个培训班的想法。乘着现在不想写代码。写一篇iOS学习路线图的文章。同时也决定出一系列的学习教程。
iOS开发的人相对于以前来说已经慢慢多起来了。但是不管从质量还是数量上来说都明显感觉不够。大学里面应该很少有iOS开发课程的。iOS开发前期投入比较高——你得先买一台苹果电脑才能开始学习iOS开发。这些限制使得iOS程序员数量跟不上企业的需求。由于物以稀为贵,这也使得iOS程序员的工资普遍也还不错。
言归正传,上学的时候我看了不少学习方法的书。其中无非就是以下几点:
这个系列的教材我将按照这些学习规律进行设计。本系类教材内容主要是帮助零基础的同学进入iOS开发的领域,并能通过它找到一份能让你养家糊口的工作。教材的前期会快速的带大家进入iOS开发。以便在你学习热情还没有消散的情况下让你快速入门。后面会逐渐补充上对大家以后有帮助的知识。换句话说,前面部分是让你会走,而后面部分是让你走的更远。同时在大家能做项目的时候,我也会附上我工作中的一些经历与感受。希望能让大家在工作上少走点弯路。
啰嗦了这么多,接下来看看教程的列表。
零基础的人首先可以快速的学习C语言,从而了解什么是编程语言。如何使用编程语言与计算机进行交流,并指导其完成机械的任务。学习完这一阶段之后我们可以使用编程语言来完成一些简单的任务。