280篇 Default中的文章

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 ~

python面试官问你用过列表推导式吗

推导式?什么东西?我还真头一回听说这名词,以为是链表、二叉树之类的问题,面试官这样问,只能摇头不解。

回来查下推导式,原来就是常用的list的for in for,有点想笑,这么简单的列表创建问题问得让我摸不着头脑,有些术语听起来很深奥,其实就是常用的表达式,这好比你去问别人设计模式,你用过什么设计模式,什么工是工厂模式?什么是单例模式等等,虽然对术语可能一知半解或者解释不清,其实就是常常在用的。

newlist = [i for i in range(1, 100) if i%3==0]
More ~

常用的公共DNS

名称 DNS 服务器 IP 地址 备用
114 DNS 114.114.114.114 114.114.115.115
阿里 AliDNS 223.5.5.5 223.6.6.6
百度 BaiduDNS 180.76.76.76
DNSPod DNS+ 119.29.29.29 182.254.116.116
CNNIC SDNS 1.2.4.8 210.2.4.8
oneDNS 117.50.11.11 52.80.66.66
DNS派 电信/移动/铁通 101.226.4.6 218.30.118.6
DNS派 联通 123.125.81.6 140.207.198.6
Cloudflare DNS 1.1.1.1 1.0.0.1
Google DNS 8.8.8.8 8.8.4.4
IBM Quad9 9.9.9.9
OpenDNS 208.67.222.222 208.67.220.220
V2EX DNS 199.91.73.222 178.79.131.110
More ~

很诡异的301跳转,记wordpress上线问题

话说本地用docker-compose搭了个wordpress的站点,设置里site url和home都是本地地址http://localhost:8300 ,然后上线的数据库数据是导出后导入进来。

用nginx反向代理wordpress的容器地址,浏览器卡住半天自动跳转到www.xxx.com:8300, 这很诡异啊,一直在怀疑是不是nginx配错了,proxy_redirect是off的。 即使重新安装nigix也无济无事。 curl -i 看看响应头确实301跳转了

Screen Shot 2019-07-22 at 01.15.02.png

More ~

docker untag? How to remove a tagged image which used docker tag

There is no docker untag command, so, the answer is find the repository which using the image and execute
docker rmi <REPOSITORY>:<TAG>

There are the commands we executed before to tag a new image with an image id

docker tag <image id> hkccr.ccs.tencentyun.com/xxx/fff:v0.1.4

And remove the tagged image
docker rmi hkccr.ccs.tencentyun.com/xxx/fff:v0.1.4

More ~

mac上定时提醒常喝水、多注意休息

Linux的定时功能crontab同样在macos上也可以用。

起因是之前检查过有尿结石,最近小腹疼,还尿出血,感觉又有结石了,所以还是要多喝水,所以写个定时提醒来时刻提醒自己。

先写段shell脚本来设置提醒内容
文件命令为 drink.sh

title="日常提醒"
content="常喝水,常排尿,远离疾病, 爱你的亲"
subtitle="记得喝水"
sound="Pon"
cmd=$(printf 'display notification "%s" with title "%s" subtitle "%s" sound name "%s"' "$content" "$title" "$subtitle" "$sound")
osascript -e "$cmd" 
say -v Ting-ting $content 
More ~

在mac命令行执行显示通知

需要用的工具:
osascript在macos上可以执行AppleScript, JavaScript等.
这里介绍AppleScript两个常用命令: display, say.

display

这个命令可以在mac上发送系统通知,macos 会在侧边栏显示这个通知消息。
AppleStript这样写 display notification "hello world!"

为了执行这条命令需要用到osascript, 并且需要-e参数,后面跟的单引号字符引用的命令
执行发送这条通知:
osascript -e 'display notification "hello world!"'

Screen Shot 2019-07-17 at 12.31.58.png

这条通知显示在屏幕右上角,3秒后消失。

More ~