- 博客(377)
- 资源 (8)
- 收藏
- 关注
原创 让git在Mac上有提示
git作为一个跨平台的工具,对于大部分码农来讲,基本是日常工作绕不过的工具。Windows和Linux平台还好,只要你安装好了,tab键一摁,提示就跟着出来了,比如后面可以用啥参数,你要切到哪个分支等等。但是水果的macOS有点不友好,你要是在你mac上只是刚刚装好了git,在terminal中只能给你提示git命令,git后面具体是啥,它就提示不了了,这着实让被那些提示功能宠坏的农农们不爽……没有提示就不能解决了吗,只能一个字符一个字符地往终端里敲么,答案肯定是no来来来,下面就是解决问题的步骤:
2020-12-26 23:13:23
2331
原创 [JS] 计算数组中最大的N个元素
const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n);测试:maxN([1, 2, 3]); // [3]maxN([1, 2, 3], 2); // [3,2]注意,如果直接是arr.sort()的话,arr本身就会被排序,所以用[...arr].sort,相当于做了一次复制。...
2019-12-24 13:06:59
3501
原创 [C++ STL] list::resize()
list::resize(),看下例子就理解了,重新设置容器尺寸,如果想要的长度比原长度小,那么截处后面的元素,如果要比原尺寸大,那就后面补默认值。string的话就是空字符串,bool的话就是false:#include<iostream>#include<list>int main(){ // Creating a list std::list...
2019-12-24 11:54:16
2245
原创 [C++ STL] list::swap()
list::swap() 交换两个容器中的元素,前提是元素类型相同:#include <iostream>#include <list>int main(){ // list container declaration std::list<int> mylist1{1, 2, 3, 4, 5, 6}; std::list<...
2019-12-23 20:15:01
4179
原创 [C++ STL] list::back()
list::back(),输出容器中最后一个元素:#include<iostream>#include<list>int main(){ // Initialization of list std::list<int> _list; // Adding elements to the list _list.push_bac...
2019-12-23 20:05:31
1774
原创 [JS] Flatten array
拍平数组,这个在lodash里也是很常见的方法,那自己实现一个看看:const flatten = arr => [].concat(...arr.map(v => (Array.isArray(v) ? v : [v])));测试Flatten([1, [2], [[3], 4], 5]); // [1, 2, [3], 4, 5]逻辑很简单,如果元素是数组的话,那就直接...
2019-12-23 19:50:20
454
原创 [JS] 寻找Object中满足条件的最后一个key
const findLastKey = (obj, fn) => Object.keys(obj).reverse() .find(key => fn(obj[key], key, obj));测试:findLastKey( { barney: { age: 36, active: true }, fred: { age: 40, active: false ...
2019-12-23 19:30:29
2161
原创 [C++ STL] list::merge()
#include<iostream>#include<list>int main(){ // declaring the lists // initially sorted, use sort() if unsorted std::list<int> list1 = { 10, 20, 30 }; std::list<...
2019-12-23 19:19:54
1340
原创 [JS] 检查一个对象是否可迭代
检查一个对象是否可迭代,也就是说这个对象是否可用迭代器遍历,比如字符串,数组……怎么检查,很简单,只要看看对象下面Symbol.iterator是不是function就行了:const isIterable = obj => obj != null && typeof obj[Symbol.iterator] === 'function';测试:isArrayLik...
2019-12-23 19:11:54
7165
原创 [JS] 变量提升
猜猜下面的代码会输出什么东东?var foo = 1;var foobar = function() { console.log(foo); var foo = 2;};foobar();如果你知道局部变量这个概念的话,你可能会觉得这个输出是foo is not defined。如果你还知道JS里有变量提升这个概念的话,你可能觉得这个输出会是2。如果你还知道JS里的变量...
2019-12-23 19:05:09
182
原创 [JS] 格式化时间长度(formatDuration)
一般来讲我们拿到的时间长度是以毫秒(millisecond)为单位的,例如34325055574,那么问题来了,一眼看去不知道这到底是多长时间,只是隐隐感觉比较长,那么我们需要转换一下:const formatDuration = ms => { if (ms < 0) ms = -ms; const time = { day: Math.floor(ms / 864...
2019-12-23 18:33:18
4052
原创 npm生成的package.json文件中依赖项版本号前的波浪号(~)和插入符号(^)是啥意思?
package.json一般也就长这么模样:{ "name": "", "description": "", "version": "4.17.1", "author": "", "contributors": [], "license": "MIT", "repository": "", "homepage": "", "keywords": [], "...
2019-07-04 15:37:52
5545
原创 推荐几个关于学习编程的GitHub仓库
GitHub全球最大的源码版本控制及托管站点,在这个站点上托管代码当时是第一位,但是对于学习资源的托管,GitHub也是相当优秀的,以下是强烈推荐每个开发者的5个GitHub仓库:1. Free Learning Resources这是一个汇集了来自世界各地的各种语言的免费学习资料。它包括书籍,网站,播客等等。大家可以试试遵循这个仓库。2. Papers With Code如果你正在学习机...
2019-06-25 19:20:47
1488
翻译 开发人员必备的13项技能
原文地址:13 Technical Skills You Should Have As A Developer如果你是计算机科学专业的学生或正在修读软件工程师或软件开发人员的课程,那么你需要掌握一些技术技能才能成为优秀的程序员。技术面广,市场上出现了很多工具,平台和语言。你是一位经验丰富的程序员还是新手菜鸟这并不重要,作为一名现代开发人员,你应该知道如何将现代技术和其他技术内容集成到你的工作中以...
2019-06-25 13:10:27
10824
1
原创 Git:重新提交没有更新的commit
应用场景一般来讲,我们push一个commit的流程是这样的:$ git add <file>$ git commit -m "commit message"$ git push origin branch-name 这时候一般Jenkins会在后台开始build项目,那么如果Build环境不太稳定的话(不是更改代码导致的),那么这次commit很可能就会build失败,那...
2019-03-27 10:58:52
10369
1
原创 JavaScript中Number类下几个常见的方法
toPrecision()很简单,toPrecision( )方法用于对数字格式化到指定精度。看例子:const num = 213.45689;console.log(num.toPrecision());console.log(num.toPrecision(4));console.log(num.toPrecision(12));console.log(num.toPrecis...
2019-03-25 15:31:41
3092
3
原创 JavaScript中Object的create和assign方法
Object.assign()这个方法是用于拷贝JSON对象的,复制对象的可枚举属性。Object.assign(target, ...sources)target是目标对象,source是原对象,返回目标对象。看例子:let returnedValue = Object.assign({ a: 1, b: 2 }, { c: 4, d: 5 });console.log(retur...
2019-03-01 22:02:43
608
原创 JavaScript中Object.getOwnPropertyNames()与Object.keys(obj)的区别
大部分情况下Object.getOwnPropertyNames()与Object.keys(obj)的功能是一样的,我们一般也是用来获取一个JSON对象中所有属性,例如const obj = { property1: 1, property2: 2,};console.log(Object.keys(obj));console.log(Object.getOwnProp...
2019-03-01 18:01:14
10993
4
转载 《原则》之生活原则——[美] 瑞·达利欧——刘波 等译——中信出版社
一、拥抱现实,应对现实1.1 做一个超级现实的人 - 梦想+现实+决心=成功的生活。1.2 真相(或者更精确地说,对现实的精确理解)是任何良好结果的根本依据。1.3 做到头脑极度开放,极度透明 - 对于快速学习和有效改变而言,头脑极度开放、极度透明是价值无限的。 - 不要担心其他人的看法,使之成为你的障碍。 - 拥抱极度求真和极度透明将带来更有意义的工作和更有意义的人际关系。1...
2018-12-23 21:31:49
1155
原创 Git: 恢复被删除的分支(Restore the deleted branch)
一般来讲,当我们的分支已经合并到了master,那么我们会删除本地和远程的分支,用下面的命令:git branch -d <your-branch>或者git branch -D <your-branch>下面这个-D表示强制删除。那么有时候就会手贱,甩开膀子写了一大堆代码,一不小心,你把分支给干掉了,更可气的是你用的-D强制删除,这咋办,别着急,想办法恢复。...
2018-10-29 21:46:55
10364
4
原创 如何设计RESTful API
每次开工前,设计API也是十分重要的一个环节,现在RESTful API大行其道,那么如何才能设计出好的RESTful API呢,也就是说我们在设计RESTful API需要遵循哪些原则呢?1、使用名词,别使用动词我们知道RESTful API是一种面向资源(resource)设计的API,那么既然是面向资源,那自然用名词更合适,这个比较好理解吧。/computers #推荐/run...
2018-06-22 17:19:23
2211
1
原创 Git: remote: Invalid username or password
$ git pullremote: Invalid username or password.fatal: Authentication failed for 'https://github.com/project/project.git/'执行git pull的时候,会出现用户名或者密码错误的提示,解决办法,执行:git push这时候会弹出一个对话框,然后输入正确的用户名和密码...
2018-06-19 11:51:52
20200
3
翻译 微服务生态系统及生产可用概要
微服务生态系统第一层:微服务硬件生态系统物理服务器(公司自有的或者从云供应商租的)数据库(专用的或者共享的)操作系统资源的隔离和抽取配置管理主机级的监控主机级的日志第二层:微服务通信生态系统网络DNS远程过程调用端点消息服务发现服务注册负载均第三层:应用平台自服务内部的开发工具开发环境测试,打包,构建,发布工具部署流程微服...
2018-06-11 22:20:59
635
原创 ES6的几个新特征
废话少说,还是直接上代码吧。1、参数默认值以前是这么写的:var link = function (height, color, url) { var height = height || 50 var color = color || 'red' var url = url || 'http://azat.co' ...}很显然以前的写法有点技巧...
2018-06-06 22:46:01
1039
原创 Git撤销本地commit
本人总是干这种挫事情:一顿操作猛如虎,各种git add,各种git commit,最后一看,我擦,还特么在master上,太吓人了,这咋办?——撤销commit:$ git commit -m "commit on master"$ git reset HEAD~ 这样撤销了上面的commit。 后续该回滚回滚,该新建分支新建分支。最后切记,时刻查看当前branch是个好...
2018-04-18 19:45:50
91052
6
原创 git: error: cannot lock ref, error: cannot lock ref
在执行git pull的时候会出现这样的错误:$ git pullerror: cannot lock ref 'refs/remotes/origin/branch': 'refs/remotes/origin/branch/repair' exists; cannot create 'refs/remotes/origin/branch'From git.microsoft.com:o...
2018-04-16 13:48:55
5902
原创 https git clone与ssh git clone之间的区别
首先看一下两种使用方法的面相:https git clone是长这样的:git clone https://github.com/project/repo.gitssh git clone是长这样的:git clone git@github.com:project/repo.git区别就是所用的协议不同:https用443端口,可以对repo根据权限进行读写,只要有账号密...
2018-04-10 18:10:08
39397
1
原创 Git: There is no tracking information for the current branch.
在执行git pull的时候,提示当前branch没有跟踪信息:git pullThere is no tracking information for the current branch.Please specify which branch you want to merge with.对于这种情况有两种解决办法,就比如说要操作master吧,一种是直接指定远程master:...
2018-03-29 10:29:22
92515
13
原创 Git: This branch is out-of-date with the base branch
有时候在你提交自己的branch后,会出现这样的情况: 如果是这样的话,那就说明该branch已经过时了,并且即使通过了所有的检测,也不能合并该branch到master,那该怎么办呢?首先要切回到mastergit checkout master切到master以后,更新master到最新:git pull这时候再切回到自己的branch:git check...
2018-03-28 10:56:13
3023
原创 Rails db rake命令
db:create 在当前的RAILS_ENV环境创建数据库,如果这个环境变量没有设好,那就默认创建开发和测试数据库。db:create:all 为所有的环境创建数据库,比如开发,测试,生产环境等。db:drop 删掉指定环境的库,如果没有指定的话,就删掉开发测试的数据库,与第一条一个意思。db:drop:all 干掉所有环境的数据库。db:migrate 跑一下当前环境的migrati...
2018-03-07 17:11:39
3054
原创 在Mac上安装consolas字体
Mac上一般不会预装consolas字体,但是作为一枚码农,没有consolas字体,无论是敲代码还是敲命令,总感觉不得劲儿,就像菜里没放盐一样,所以想想还得把这个字体装上。本文参考了http://ikato.com/blog/how-to-install-consolas-font-on-mac-os-x.html$ brew install cabextract$ cd ~/Down...
2018-03-06 15:56:54
10514
原创 双重哈希
双重哈希属于开放地址哈希中的一种解决冲突方案,也就是说如果一次哈希不能解决问题的时候,要再次哈希,与再哈希方法不同的是,第二次使用的哈希函数与第一次是不同的:(hash1(key) + i * hash2(key)) % TABLE_SIZE一般来讲,hash1(key) = key % TABLE_SIZEhash2(key) = PRIME – (key % PRIME)...
2018-02-24 22:19:54
11788
1
原创 error: cannot lock ref 'a/b/c/d' exists; cannot create 'a/b/c/d'
在使用git pull的时候出现这样的错误。解决办法: 首先要删除引用,有多少删除多少:git update-ref -d a/b/c/d然后在使用:git pull实在不行就使用:git pull origin master
2018-02-06 13:59:23
3033
原创 Binary Tree Inorder Traversal
题目地址:https://leetcode.com/problems/binary-tree-inorder-traversal/description/Given a binary tree, return the inorder traversal of its nodes’ values.For example: Given binary tree [1,null,2,3],
2018-01-21 12:53:44
339
原创 Daily Temperatures
题目地址:https://leetcode.com/problems/daily-temperatures/description/Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait u
2018-01-20 23:08:20
347
原创 Unique Paths
题目地址:https://leetcode.com/problems/unique-paths/description/A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or r
2018-01-20 17:36:21
211
原创 Merge Intervals
题目地址:https://leetcode.com/problems/merge-intervals/description/Given a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10]
2018-01-20 16:37:20
285
原创 Partition List
题目地址:https://leetcode.com/problems/partition-list/description/Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You shoul
2018-01-20 12:51:54
226
原创 Search a 2D Matrix
题目地址:https://leetcode.com/problems/search-a-2d-matrix/description/Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in e
2018-01-14 17:53:40
170
原创 Simplify Path
题目地址:https://leetcode.com/problems/simplify-path/description/Given an absolute path for a file (Unix-style), simplify it.For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c
2018-01-13 21:06:47
187
OSGi in Action
2017-10-05
apt-mirror-api-0.1.jar
2016-11-15
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人