john's tech blog

hope is coming


  • 首页

  • 标签

  • 归档

scala_config

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

scala typesafe config库读取配置

这两天在看一个akka remote actor future超时的问题

之前的超时是在remoteActor里配置的

1
def remoteActor = TypedActor.context.system.actorSelection(actorInfo.remoteActorPath)

然后调用的时候是用

1
Await.result(remoteActor.?(GetCarMonthlyInfo(date,parkCode))(Timeout.intToTimeout(5000000)), timeout)

结果发现还是会出现

times out in 5000 ms```
1
2
3
4
5
6
7
8
9

问题出在哪里呢?

其实出在TypedActor本身,默认配置读取的jar包里的reference.conf
```java
typed {
# Default timeout for typed actor methods with non-void return type
timeout = 5s
}

1
TypedActor(system).DefaultReturnTimeout

这里的配置会和应用的配置文件合并

1
2
3
4
5
6
7
final val config: Config = {
//cfg 应用配置文件
//defaultReference 默认配置
val config = cfg.withFallback(ConfigFactory.defaultReference(classLoader))
config.checkValid(ConfigFactory.defaultReference(classLoader), "akka")
config
}

路径:config-1.2.1-sources.jar!\com\typesafe\config\impl\AbstractConfigValue.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public AbstractConfigValue withFallback(ConfigMergeable mergeable) {
if (ignoresFallbacks()) {
return this;
} else {
ConfigValue other = ((MergeableValue) mergeable).toFallbackValue();

if (other instanceof Unmergeable) {
return mergedWithTheUnmergeable((Unmergeable) other);
} else if (other instanceof AbstractConfigObject) {
return mergedWithObject((AbstractConfigObject) other);
} else {
return mergedWithNonObject((AbstractConfigValue) other);
}
}
}

Angular路由组件newRouter

发表于 2017-06-19 | 更新于 2019-05-10

ngNewRouter

项目中使用ngNewRouter,看它的源码时候发现了

gulp-traceur 是由Sindre Sorhus开发的

看网上说是国外23位知名JavaScript开发者之一

里面源码涉及到了angular injector中的factory函数

uglifyjs_purefuncs

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

今天在看我推荐的一些前端开发工具

这篇文章时,看到‘之后上线时,可以使用uglify压缩掉所有console的代码’ 这段话,

我就琢磨uglify怎么把console去掉,然后就打开UglifyJS2

看文档,有如下描述:

pure_funcs – default null. You can pass an array of names and UglifyJS will assume that those functions do not produce side effects. DANGER: will not check if the name is redefined in scope. An example case here, for instance var q = Math.floor(a/b). If variable q is not used elsewhere, UglifyJS will drop it, but will still keep the Math.floor(a/b), not knowing what it does. You can pass pure_funcs: [ ‘Math.floor’ ] to let it know that this function won’t produce any side effect, in which case the whole statement would get discarded. The current implementation adds some overhead (compression will be slower).

drop_console – default false. Pass true to discard calls to console.* functions. If you wish to drop a specific function call such as console.info and/or retain side effects from function arguments after dropping the function call then use pure_funcs instead.

我就写了个例子测试下:

1
2
3
4
function test(){
return "ss";
}
console.info(test());

运行如下命令

test.js --compress pure_funcs=['console.info'] -o test.min.js ```
1
2

会得到如下输出```function test(){return"ss"}test()

运行如下命令

test.js --compress pure_funcs=['console.info','test'] -o test.min.js ```
1
2

会得到如下输出```function test(){return"ss"}

运行如下命令

test.js --compress drop_console=true -o test.min.js```
1
2

会得到如下输出```function test(){return"ss"}

参考资料:
UglifyJS中文文档
小tip:我是如何初体验uglifyjs压缩JS的

nodejs的命令行是如何调用的

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

nodejs命令是从哪里调用的

研究了下hexo的命令调用

npm config

运行了下 npn config list命令,输出如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
; cli configs
scope = ""
user-agent = "npm/4.2.0 node/v7.10.0 win32 x64"

; userconfig C:\Users\Administrator\.npmrc
cache = "D:\\npmcache"
prefix = "D:\\npmglobal"

registry = "https://registry.npm.taobao.org/"

; builtin config undefined

; node bin location = D:\nodejs\node.exe
; cwd = F:\code\blognew
; HOME = C:\Users\Administrator
; "npm config ls -l" to show all defaults.

prefix和cache是npm的全局路径,

我们到该目录下发现有个hexo.cmd和hexo 文件,打开hexo.cmd,代码如下:

1
2
3
4
5
6
7
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\node_modules\hexo-cli\bin\hexo" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\node_modules\hexo-cli\bin\hexo" %*
)

那我们就到当前目录的node_modules中看

1
2
3
4
5
6
7
8
9

```js
#!/usr/bin/env node

'use strict';

require('../lib/hexo')();

console.log('hi');

在任意目录下执行hexo命令会输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
hi
Usage: hexo <command>

Commands:
help Get help on a command.
init Create a new Hexo folder.
version Display version information.

Global Options:
--config Specify config file instead of using _config.yml
--cwd Specify the CWD
--debug Display all verbose messages in the terminal
--draft Display draft posts
--safe Disable all plugins and scripts
--silent Hide output on console

For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/

DOS批处理

DOS批处理命令:
%~dp0 代表当前目录

SETLOCAL
开始批处理文件中环境改动的本地化操作。在执行 SETLOCAL 之后所做的环境改动只限于批处理文件。要还原原先的设置,必须执行 ENDLOCAL。 达到批处理文件结尾时,对于该批处理文件的每个尚未执行的 SETLOCAL 命令,都会有一个隐含的 ENDLOCAL 被执行。

PathExt修改 让我们的Bat文件执行的优先级别在其他可执行文件之前就OK了
DOS批处理中%~dp0表示什么意思
批处理,%~d0 cd %~dp0 代表什么意思
cmd SETLOCAL使用介绍
修改Pathext,让你的东东优先执行

angular_injector5

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

angular injector 剖析流程

angular中的注入器是承载angular整个运行的基石,如果想弄清楚angular的来龙去脉,那injector这块必须得熟悉。

createInjector

createInjector方法是入口函数,方法参数是modulesToLoad和strictDi,

我们主要关注modulesToLoad参数,字面含义就是待加载的模块。

providerCache

函数一开始就定义了providerCache对象,顾名思义就是提供provider的缓存。

providerCache内部又定义了$provide对象属性,暂且不管。

providerInjector

定义provider的注入器,同时也定义了providerCache.$injector.
最终是返回一个用于提供protoInstanceInjector查找instance的方法对象

publishExternalAPI

通过setupModuleLoader 方法,顾名思义为设置模块加载器, 定义了 angularModule 对象为angular.module方法

里面很重要的一个方法就是

1
2
3
function ensure(obj, name, factory) {
return obj[name] || (obj[name] = factory());
}

随之定义了angular.module(‘ng’,[‘ngLocale’], [‘$provide’,function($provide){}])

把ng模块放入了modules对象集合

先是定义

config = invokeLater('$injector', 'invoke', 'push', configBlocks);```
1
2
3
4
5
6
7
8
9
10
11

##### invokeLater

```js
function invokeLater(provider, method, insertMethod, queue) {
if (!queue) queue = invokeQueue;
return function() {
queue[insertMethod || 'push']([provider, method, arguments]);
return moduleInstance;
};
}

通过以下方法把

1
2
3
4
5

```js
if (configFn) {
config(configFn);
}

configBlocks一开始定义为空数组,然后push 了一个数组对象['$injector','invoke',['$provide',function($provide){}]]

下篇文章继续分析push了以后是从哪调用的。

1…202122…47

John

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