276篇 Default中的文章

npm离线安装包及依赖

虚机无法联外网场景下需要安装npm包,找到这个办法:

  1. 在本地安装npm-bundle
    npm install -g npm-bundle

  2. 在本地安装使用npm-bundle下载需要的npm包及依赖,如需要安装json-server, 一个伪server提供api测试场景。https://github.com/typicode/json-server
    npm-bundle json-server, 执行上述命令后会在当前文件目录新建 json-server-0.15.0.tgz

  3. 上传json-server-0.15.0.tgz到虚机中,执行安装
    npm install -g ./json-server-0.15.0.tgz

done.

More ~

python中执行shell command

python3 适用,执行shell命令

使用subprocess

import subprocess

def run(args):
    out = subprocess.Popen(args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
    stdout, stderr = out.communicate()
    return stdout

print(run(['ls', '-l']))

使用os.system

import os
os.system('ps -ef')

使用os.popen

import os
os.popen('ls')
More ~

JSONPath

##jsonpath的语法

符号 描述
$ 查询的根节点对象,用于表示一个json数据,可以是数组或对象
@ 过滤器断言(filter predicate)处理的当前节点对象,类似于java中的this字段
* 通配符,可以表示一个名字或数字
.. 可以理解为递归搜索,Deep scan. Available anywhere a name is required.
. 表示一个子节点
[‘’ (, ‘’)] 表示一个或多个子节点
[ (, )] 表示一个或多个数组下标
[start:end] 数组片段,区间为[start,end),不包含end
[?()] 过滤器表达式,表达式结果必须是boolean
More ~

docker images filter 镜像查询过滤

找出tag为<none>
docker images -f "dangling=true"

找出tag为<none>的, 只返回image id
docker images -f "dangling=true" -q

根据repository名称和tag模糊过滤,我验证时,如果repository有/或小数点符号,通过*是无法匹配的
docker images --filter=reference='busy*:*libc'

使用beforesince根据时间查找,实际上以repository的名字作为时间分隔,
docker images --filter "before=image1"

docker images --filter "since=image3"

此外还有label, label=<key> or label=<key>=<value>
docker images --filter "label=com.example.version" , 这条我用docker image inspect <image id>,发现几个image的label都是空的,这个有待研究。

More ~

git: error: unable to locate xcodebuild

The issue is:
When I open pycharm git project, it displays the error:
WX20190806-221556.png

Cannot Run Git
git: error: unable to locate xcodebuild, please make sure the path to the Xcode folder is set correctly! git: error: You can set the path to the Xcode folder using /usr/bin/xcode-select -switch

And I try git command in the Terminal, it's same error.

There I found the solution on stackoverflow:
Run this command:
sudo xcode-select --switch /Library/Developer/CommandLineTools/

WX20190806-222115.png

More ~

《无主之城》江雪反入侵之神秘脚本

最近看到国产网剧《无主之城》,感觉大有僵尸之类美剧的情节,看到第10集,江雪的电脑被入侵后,江雪在键盘上霹雳啪啦一顿狂操作,画面切到一堆黑屏的命令窗口,有点好奇是什么命令,遂暂停截了下图:

Screen Shot 2019-08-05 at 01.04.59.png

原来桌面用的黑色背景,命令窗口调用几个批处理命令打印出代码。代码的内容还是用Python的pygame库加载声音文件,设置音量。
而且几个窗口的内容是一样的!
和网络命令也不沾边,看来也就是做做效果,糊弄一下。

More ~

MacOS app renders blank screen with WKWebView

I'm not sure there are differences of WKWebView usage between iOS app and MacOS app. There I have an issue that a web view on the storyboard can not load a request. Typically there is always the white screen, implies nothing loads.

Finally, I found the solution here. In the Capabilities tab of the project target, it's App Sandbox, check the Network: Outgoing Connections (Client).

Screen Shot 2019-07-25 at 22.28.10.png

More ~

python中的*args 和 **kwargs

*args**kwargs 均为可变参数,方便记忆可以理解为 *args是列表形式的多个参数,不过它传值不是以list, 就是func(arg1, arg2, arg3...)
**kwargs可以理解为字典形式的多组key, value键值对,不过它传值也不是字典,而是func(a=1, b=2, c=3...)。

它们同时出现在func的定义中时,*args在前, **kwargs在后

**kwargs通常用在类的初始化多个配置项参数值传递。举一个pymongo的例子:

class MongoClient(common.BaseObject):
    def __init__(
            self,
            host=None,
            port=None,
            document_class=dict,
            tz_aware=None,
            connect=None,
            type_registry=None,
            **kwargs):
More ~