john's tech blog

hope is coming


  • 首页

  • 标签

  • 归档

sbt linux shell脚本解读

发表于 2017-06-14 | 更新于 2019-05-07

set -e

你写的每个脚本都应该在文件开头加上set -e,这句语句告诉bash如果任何语句的执行结果不是true则应该退出。这样的好处是防止错误像滚雪球般变大导致一个致命的错误,而这些错误本应该在之前就被处理掉。如果要增加可读性,可以使用set -o errexit,它的作用与set -e相同。

参考资料:
Unix/Linux 脚本中 “set -e” 的作用

export

set:显示(设置)shell变量 包括的私有变量以及用户变量,不同类的shell有不同的私有变量 bash,ksh,csh每中shell私有变量都不一样

env:显示(设置)用户变量变量

export:显示(设置)当前导出成用户变量的shell变量。
参考资料:
shell环境变量以及set,env,export的区别
set,env和export这三个命令的区别

1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/env bash
#
# A more capable(胜任的) sbt runner, coincidentally(巧合) also called sbt.
# Author: Paul Phillips <paulp@typesafe.com>

# todo - make this dynamic
declare -r(只读) sbt_release_version=0.12.0(sbt发布版本)
declare -r sbt_snapshot_version=0.13.0-SNAPSHOT

unset(unset为shell内建指令,可删除变量或函数) sbt_jar sbt_dir sbt_create sbt_snapshot sbt_launch_dir
unset scala_version java_home sbt_explicit_version
unset verbose debug quiet

/usr/bin/env

在linux的一些脚本里,需在开头一行指定脚本的解释程序,如:

python```
1
2
3
4
5

再如:
```linux
#!/usr/bin/env perl
#!/usr/bin/env zimbu

但有时候也用

1
#!/usr/bin/python

和

1
#!/usr/bin/perl

那么 env到底有什么用?何时用这个呢?
脚本用env启动的原因,是因为脚本解释器在linux中可能被安装于不同的目录,env可以在系统的PATH目录中查找。同时,env还规定一些系统环境变量。

执行一下 env 命令后看看打印的内容

可以用env来执行程序:

参考资料:
使用/usr/bin/env的好处
#!/usr/bin/env bash和#!/usr/bin/bash的比较
Linux set unset命令

html的base节点

发表于 2017-06-14 | 更新于 2019-05-07

这可是高科技了。举个例子。
假如你这个页面的a标签是这样写的;
text link
默认就是本页面打开;
但是你加了

那这个链接就是新页面打开

再比如:你的a标签还是这么写的

text link

默认打开的网址就是现在的相对路径下的xxx.html
假如你加了


那你刚才的那个链接打开的地址就是
http://www.baidu.com/xxx.html
base这个东西有点编程语言里的全局变量;
如果你要改变这个也是可以的。就是在你要改变的A标签里重写它定义的属性,比如刚才的链接你写成这样text link
即使你定义了 这个加了target的A链接依然是当前页面打开;

转载自:
在html中base的作用是什么

scala的Either类型

发表于 2017-06-13 | 更新于 2019-05-07

这一段要弄清楚:

1
2
3
4
5
6
7
8
def averageLineCountWontCompile(url1: URL, url2: URL): Either[String, Int] =
for {
source1 <- getContent(url1).right
source2 <- getContent(url2).right
lines1 = source1.getLines().size
lines2 = source2.getLines().size
}
yield (lines1 + lines2) / 2

参考博文:
类型 Either

javascript_promise

发表于 2017-06-07 | 更新于 2019-05-07

前端面试1

promise

1
2
3
4
5
6
7
8
9
10
11
12
13
setTimeout(function() {
console.log(1)
}, 0);
new Promise(function executor(resolve) {
console.log(2);
for( var i=0 ; i<10000 ; i++ ) {
i == 9999 && resolve();
}
console.log(3);
}).then(function() {
console.log(4);
});
console.log(5);

首先先碰到一个 setTimeout,于是会先设置一个定时,在定时结束后将传递这个函数放到任务队列里面,因此开始肯定不会输出 1 。

然后是一个 Promise,里面的函数是直接执行的,因此应该直接输出 2 3 。

然后,Promise 的 then 应当会放到当前 tick 的最后,但是还是在当前 tick 中。

因此,应当先输出 5,然后再输出 4 。

最后在到下一个 tick,就是 1 。

“2 3 5 4 1”

参考资料:
Excuse me?这个前端面试在搞事!

angular_api

发表于 2017-06-06 | 更新于 2019-05-07

angular 基础api介绍

angular.isString

angular.isString判断输入参数是否是字符串,源码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* @ngdoc function
* @name angular.isString
* @module ng
* @kind function 函数
*
* @description
* Determines if a reference is a `String`.
*
* @param {*} value Reference to check. 参数
* @returns {boolean} True if `value` is a `String`. 返回
*/

function isString(value) {return typeof value === 'string';}

angular.isObject

angular.isObject 判断输入参数是否是Object类型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* @ngdoc function
* @name angular.isObject
* @module ng
* @kind function
*
* @description
* Determines if a reference is an `Object`. Unlike `typeof` in JavaScript, `null`s are not
* considered to be objects. Note that JavaScript arrays are objects.
在angular中null是不被考虑为object的。 JavaScript的array是object
*
* @param {*} value Reference to check.
* @returns {boolean} True if `value` is an `Object` but not `null`.
*/

function isObject(value) {
// http://jsperf.com/isobject4
return value !== null && typeof value === 'object';
}

angular.isNullObject

判断引用参数是否是带空原型链的对象

1
2
3
4
5
6
7
8
9
10
/**
* Determine if a value is an object with a null prototype

*
* @returns {boolean} True if `value` is an `Object` with a null prototype
*/

function isBlankObject(value) {
//var getPrototypeOf = Object.getPrototypeOf,
return value !== null && typeof value === 'object' && !getPrototypeOf(value);
}

isArrayLike

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @private
* @param {*} obj
* @return {boolean} Returns true if `obj` is an array or array-like object (NodeList, Arguments,
* String ...)
如果obj参数是数组或者类似数组的对象(节点列表,参数,字符串)
*/

function isArrayLike(obj) {

//null undefined window 不是array-like
// `null`, `undefined` and `window` are not array-like
if (obj == null || isWindow(obj)) return false;

// arrays, strings and jQuery/jqLite objects are array like
// * jqLite is either the jQuery or jqLite constructor function
// * we have to check the existence of jqLite first as this method is called
//必须先检测jqLite是否存在
//因为当jqLite实例化时forEach调用了这个方法
// via the forEach method when constructing the jqLite object in the first place
if (isArray(obj) || isString(obj) || (jqLite && obj instanceof jqLite)) return true;

// Support: iOS 8.2 (not reproducible in simulator)
// "length" in obj used to prevent JIT error (gh-11508)
var length = "length" in Object(obj) && obj.length;

// NodeList objects (with `item` method) and
// other objects with suitable length characteristics are array-like
return isNumber(length) &&
(length >= 0 && ((length - 1) in obj || obj instanceof Array) || typeof obj.item == 'function');

}
1…222324…47

John

232 日志
43 标签
GitHub Twitter
欢迎关注我的公众号:沉迷Spring
© 2023 johnwonder
由 Hexo 强力驱动 v3.2.0
|
主题 – NexT.Pisces v7.1.1
|
0%