我有这个:
str=`cat package.json`
prop="name"
my_val="$(node -e "console.log(JSON.parse(${str})[${prop}]);")"
echo "$my_val"
Run Code Online (Sandbox Code Playgroud)
我想读取namepackage.json 文件的属性。我认为这很接近,但我收到 JSON.parse 错误:
SyntaxError: Unexpected token o in JSON at position 1
at Object.parse (native)
at [eval]:1:18
at ContextifyScript.Script.runInThisContext (vm.js:25:33)
at Object.runInThisContext (vm.js:97:38)
Run Code Online (Sandbox Code Playgroud)
有人知道如何修复吗?
这有效:
prop="name"
my_val="$(node -e "console.log(require('./package.json')['$prop'])")"
echo "json val: '$my_val'"
Run Code Online (Sandbox Code Playgroud)
但我想知道如何以第一种方式做到这一点。
有没有办法使用 Object.assign 以便在顶级属性发生冲突时抛出错误?或者我们必须手动编写我们的功能才能这样做?
我有这个:
docker run -d --name my-name mongo
Run Code Online (Sandbox Code Playgroud)
有谁知道如何使用Docker运行特定版本?
就像是:
docker run -d --name my-name mongo=2.4.9
Run Code Online (Sandbox Code Playgroud)
我需要使用版本2.4.9运行mongo ...
我有一个像这样的 ReplaySubject:
matchCount = new ReplaySubject<number>();
totalCount = new ReplaySubject<number>();
Run Code Online (Sandbox Code Playgroud)
我像这样使用它:
getMatchedEventsCount(){
return this.dcs.matchCount.asObservable();
}
getTotalEventsCount(){
return this.dcs.totalCount.asObservable();
}
Run Code Online (Sandbox Code Playgroud)
我只是得到计数 - 我只需要每个重播主题的最后(最近)值,我不需要所有值。
有没有办法做到这一点?
我有下面的代码,我从这里偷了:https : //github.com/angular/material2/blob/master/src/demo-app/expansion/expansion-demo.html
<mat-expansion-panel class="mat-expansion-demo-width" #myPanel>
<mat-expansion-panel-header [expandedHeight]="expandedHeight" [collapsedHeight]="collapsedHeight">
<mat-panel-description>Click here to change view format.</mat-panel-description>
<mat-panel-title>View Controls</mat-panel-title>
</mat-expansion-panel-header>
<ng-template matExpansionPanelContent>
This is the content text that makes sense here.
<mat-checkbox>Trigger a ripple</mat-checkbox>
</ng-template>
foo bar baz
<mat-action-row>
<button mat-button (click)="myPanel.expanded = false">CANCEL</button>
</mat-action-row>
</mat-expansion-panel>
Run Code Online (Sandbox Code Playgroud)
一个问题-我很困惑,因为<ng-template>标记内的内容没有显示,但是显示了“ foo bar baz”。那么内部内容的目的是什么<ng-template>,为什么不显示呢?
我在看这篇文章。
建议为当前用户允许不带root的dtrace使用,因此我运行:
$ sudo chmod u+s /usr/sbin/dtrace
Password: # I enter in my password
chmod: Unable to change file mode on /usr/sbin/dtrace: Operation not permitted
Run Code Online (Sandbox Code Playgroud)
有谁知道我是否应该以及应该如何允许dtrace在没有root权限的情况下运行?
我有这个代码示例:
before('get all users', h => {
return getAllUsers().then(function (users) {
return h.supply.users = users;
});
});
Run Code Online (Sandbox Code Playgroud)
我正在寻找一些速记,这是我能做的最好的吗?
before('get all users', h => {
return getAllUsers().then(v => (h.supply.users = v));
});
Run Code Online (Sandbox Code Playgroud)
我在想,也许我们可以使用一些替代的分配技巧.
假设我们想要使用Node.js进程池,使用React渲染一些HTML.(我不是说这是一个好主意,只是假设是这种情况,lulz).
有没有办法将Golang的请求/响应流的引用传递给Node.js进程?我认为Node.js的集群模块使用这种技术,通过传递文件描述符或类似的东西.请注意,Node.js进程池(可能是3个进程左右)将是Golang进程的子进程.
我有这个:
const {ops} = getOplogStreamInterpreter(strm);
ops.del.subscribe(v => {
console.log('delete happened 1.');
});
ops.insert.subscribe(v => {
console.log('insert happened 1.');
});
ops.update.subscribe(v => {
console.log('update happened 1.');
});
Run Code Online (Sandbox Code Playgroud)
只是想知道是否可以以某种方式做到这一点:
const {{insert,del,update}} = getOplogStreamInterpreter(strm);
Run Code Online (Sandbox Code Playgroud)
基本上进一步解构返回的对象。
我有看起来像这样的文件夹:
foo/
Bar.java
Bar.class
Foo.java
Foo.class
manifest.mf
Run Code Online (Sandbox Code Playgroud)
.java 文件都在一个名为 x 的包中:
package x;
Run Code Online (Sandbox Code Playgroud)
我生成 .class 文件:
javac foo/*.java
Run Code Online (Sandbox Code Playgroud)
然后我尝试打包为可运行的 jar 格式:
jar cmf foo.jar foo/manifest.mf foo/*.class
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
java.io.IOException: line too long
at java.base/java.util.jar.Attributes.read(Attributes.java:381)
at java.base/java.util.jar.Manifest.read(Manifest.java:228)
at java.base/java.util.jar.Manifest.<init>(Manifest.java:80)
at java.base/java.util.jar.Manifest.<init>(Manifest.java:72)
at jdk.jartool/sun.tools.jar.Main.run(Main.java:264)
at jdk.jartool/sun.tools.jar.Main.main(Main.java:1669)
Run Code Online (Sandbox Code Playgroud)
manifest.mf 的内容只是:
Main-Class: x.Bar
Run Code Online (Sandbox Code Playgroud)
它编译时javac不确定发生了什么,或者为什么它不喜欢清单文件,有人知道吗?