踩坑合集/(不定时补充)
前后端踩坑合集
前端
Node-sass: Command failed
更改 yarn
源即可
1 | yarn config set registry https://registry.npm.taobao.org -g |
另附 npm 换源
1 | npm config set registry https://registry.npm.taobao.org |
@sentry/cli 安装错误的问题
In case of @sentry-cli problem, create .yarnrc
and write the source below into it.
1 | registry: https://registry.npm.taobao.org |
Then u will see the source is edited and show as below
node16 以上的加密部件问题
使用 node18 跑新项目时出现了这一错误
1 | error/0308010C/digital envelope routines//unsupported |
看错误报告里讲node17.0
以上的版本会出现这个情况。
nodejs 17: digital envelope routines::unsupported #14532
方案 1
环境变量里面加个变量,将OpenSSL
降回到老策略去:
1 | export NODE_OPTIONS=--openssl-legacy-provider |
方案 2
版本回退到Node.js 16
。
如果平时工作的项目所使用的node
版本不一样,通过全局频繁卸载安装的方式显然效率低下。推荐使用nvm
来安装管理node
版本,并且node
版本间的切换也非常方便。nvm
切换node
版本步骤:
1 | # 安装 node 16.13.0 版本 |
安装 nvm
运行 curl 命令时会出现以下错误:
1 | curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 14 ms: Connection refused |
github 的一些域名的 DNS 解析被污染,导致DNS 解析过程无法通过域名取得正确的IP地址。
因此我们要找到正确的这个raw.githubusercontent.com网站正确的ip地址
打开ip地址查询网站:https://www.ipaddress.com/
输入需要查询的网站名称raw.githubusercontent.com
网站上会显示该网站的存在的ipv4以及ipv6地址,这里可以选取一个ipv4地址来进行设置
打开系统host文件
1 | sudo vim /etc/hosts |
在host文件中添加一行
1 | 185.199.108.133 raw.githubusercontent.com |
最后执行
1 | sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" |
Flutter/RN iOS 联调记录
Firebase Analytics setScreenName deprecatedFirebase Analytics setScreenName 已弃用
ARC Semantic Issue (Xcode): No known class method for selector ‘setScreenName:screenClass:’
如果 react-native 中发生相同的错误,则 在 RNFirebaseAnalytics.m
文件中,更新以下代码行:
1 | [FIRAnalytics setScreenName:screenName screenClass:screenClassOverriewl; |
至
1 | [FIRAnalytics logEventWithName: kFIREventScreenView parameters: @(kFIRParameterScreenName: screenName]) |
Xcode 12 解決 Command PhaseScriptExecution failed with a nonzero exit code
在 build 專案時遇到以下錯誤時
1 | /Users/.../Script-E97175B023F12D90003B2A7E.sh: line 2: /usr/local/bin/carthage: No such file or directoryCommand PhaseScriptExecution failed with a nonzero exit code |
到 Project setting targets > Build Phases > Run Script>
勾選 ☑For install builds only
解決 Swift failed to emit precompiled header
Q: 在 OC 中引用 Swift , 需要#import “ProductName-Swift.h”, 升級之後回報failed to emit precompiled header的錯誤.
A: 在Build Settings 中, 搜索 precomplile找到Precompile Prefix Header設為YES
Vue 日期表单限制当前时间为最大可选值
接手了 Vue 项目,需要 Mint-UI 的日期表单的最大可选值设置为当前时间,也就是说只能选择现在和现在以前的时间。
官方文档看起来使用方法很简单,添加一个endDate属性,设置最大可选时间就可以了
1 | <mt-datetime-picker v-model="datetime" ref="datetimePicker" type="datetime" @confirm="this.changeTime" endDate="new Date()"> |
当然这个方法报错 endDate.getFullYear() is not a function
,endDate不是当做一个属性被编译,而是被当作一个变量被编译了,所以说明这个用法是错误的。
正确用法如下,需要在date里面给endDate赋值,比如我这里只能选择今天及之前的日期:endDate: new Date()
1 | <mt-datetime-picker v-model="datetime" ref="datetimePicker" type="datetime" @confirm="this.changeTime" :end-date="endDate"> |
Vue input 无法用 maxlength 限制长度
1、当input,type为text时,设置maxlength后,能限制输入内容长度;
2、当input,type为tel时,设置maxlength后,也是能限制输入内容长度,并且弹起键盘为默认为数字键盘;
3、当input,type为number,设置了maxlength,是无法正常限制输入内容长度的,input元素内还是可以无限的输入内容。
解决方法:a 通过监听input的输入,input事件。
1 | <input type="number" oninput="if( this.value.length > 4 ) this.value = this.value.slice(0,4)"> |
当输入超过4位后,会进行截断,保留前面的4位。
用vue,使用@input
但是会有小小不好的体验,输入第五位的时候,会先显示第五位,然后再删除第五位。因为这是通过监听input事件,来实现的。
解决方法:b 将number改为tel类型,然后设置maxlength。因为设置type为tel后,也是只能输入数字。然后只能输入相应的位数。
vue 地图开发
获取本地位置
html5 地理定位接口在许多浏览器平台都返回如下的错误信息,这是因为 html5 默认调用谷歌接口,会有安全限制。
城市区域名称转化
获取到的是经纬度,所以要调百度或者谷歌的地图api,来转换为城市。
使用腾讯地图 API 获取当前位置的经纬度
因为使用 axios 自动拼接 url 路径会产生跨域问题
1 | <!-- 在 main.js 中添加 |
使用 vue-jsonp 解决跨域问题
1 | <!-- 在 main.js 中添加 |
后端
Non-resolvable import POM
1 | mac@macdeMacBook-Pro WX-Fleas-Market-Demo % mvn clean package -Dmaven.test.skip=true |
转到发现
1 | <dependencies> |
参考了这篇博客后,知道系统文件自动将 ${spring-cloud.version}
读为 Greenwich.M1
版本。将其改成 Edgware.SR3
即可跑通。
开发代号看似没有什么规律,但实际上首字母是有顺序的,比如:Dalston版本,我们可以简称 D 版本,对应的 Edgware 版本我们可以简称 E 版本。
D、E版本:二者均基于SpringBoot的1.5.x版本,但支持其他组件的版本不同,如以 Dalston.SR4 和 Edgware.RELEASE 来对比:
- spring-cloud-config 分别对应 1.3.3和 1.4.0;
- spring-cloud-netflix 分别对应 1.3.5和 1.4.0;
- spring-cloud-consul 分别对应 1.2.1和 1.3.0;
- spring-cloud-gateway 前者不支持,后者 1.0.0。
F版本:F版本是个绝对的大版本,几乎所有组件,全部同步变更版本号为2.x;
SNAPSHOT: 小版本,快照版本,随时可能修改;
M: MileStone,小版本,M1表示第1个里程碑版本,一般同时标注PRE,表示预览版版。
SR: Service Release,小版本,SR1表示第1个正式版本,一般同时标注GA:(GenerallyAvailable),表示稳定版本。
jar missing problem
1 | [ERROR] [ERROR] Some problems were encountered while processing the POMs: |
子在pom中为他们指定版本号就好了。版本号可以在https://mvnrepository.com/ 中通过artifactId 查询
还有写项目的时候突然报了这个错误:Error:java:java.lang.ExceptionInInitializerError: com.sun.tools.javac.code.TypeTags
1 | WARNING: All illegal access operations will be denied in a future release |
然后当时就很懵逼,后来通过排错,发现是使用的lombok版本过低,我使用的springboot的版本是:: Spring Boot :: (v2.2.1.RELEASE)
package org.springframework.cloud.openfeign does not exist
没有添加版本号
没有添加以下依赖
1 | <dependency> |
开发环境配置踩坑大全
配置 maven
解压到某路径如 /usr/local/...
1 | vim ~/.bash_profile |
配置 flutter
1 | export PATH="$PATH:`pwd`/flutter/bin" |
使用 m1 GPU 训练 Tensorflow
Please try the same after creating a virtual environment.
1 | python3 -m venv ~/tensorflow-metal |
使用 bench.py
测试 m1 性能,运行时间为 108.47s(作为对比,24 核 gpu m1max 运行时间为 58s)
1 | import tensorflow as tf |
运行 TensorFlow 报错
1 | ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none) |
原因:Python的版本过高。使用指令:python –version 查看当前使用的Python版本。TensorFlow支持的Python版本只到python3.5。
解决方案:
- 把当前的Python卸载掉,安装python3.5
- 指定安装支持高版本Python的TensorFlow
1 | python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl |
tensorflow 加载数据集异常
异常错误提示:
tensorflow/core/platform/cloud/google_auth_provider.cc:184] All attempts to get a Google authentication bearer token failed, returning an empty token. Retrieving token from files failed with “Not found: Could not locate the credentials file.”. Retrieving token from GCE failed with “Failed precondition: Error executing an HTTP request: libcurl code 6 meaning ‘Couldn’t resolve host name’, error details: Couldn’t resolve host ‘metadata’”.
解决方法:改成如下对应的版本就行
tensorflow=2.3.0 and tensorflow-datasets=2.1.0
命令如下:
pip install tensorflow-datasets==2.1.0
想详细了解的同学可以去查看以下两个网址:
https://github.com/PAIR-code/lit/issues/26
https://github.com/PAIR-code/lit/issues/22
M1 安装 pytorch
1 | torch create virtual environment |
m1 安装 qemu 卡死问题
按照官网步骤使用 brew 安装 qemu 之后,make install
会卡死在第一步,在这一 issue 中找到了解决方案:
https://github.com/BASARANOMO/xv6-labs-2020/issues/1
Then, download the qemu-5.1.0 and unzip the downloaded .tar.xz
file:
1 | wget https://download.qemu.org/qemu-5.1.0.tar.xz |
Two patches are needed:
patch1: just download it and cd
to the qemu directory, then:
1 | patch -p1 < ../patch/v2-tcg-Fix-execution-on-Apple-Silicon.patch |
patch2: Two lines only. Find the file in qemu directory and modify it.
Then run configure with:
1 | ./configure --disable-kvm --disable-werror --prefix=/usr/local --target-list="riscv64-softmmu" |
1 | make |
Catalina quarantine for corrupted apps
低于 Big Sur
系统版本的 macOS
或 m1
芯片机器在安装一些未适配软件时候可能会出现 安装包损坏, 打不开“XXX”,因为它来自身份不明的开发者
等报错,在此状态下可以尝试以下做法。
1 | sudo spctl --master-disable |
(以及 Catalina 真的好耐看啊!)
Homebrew国内源
https://gitee.com/cunkai/HomebrewCN
苹果电脑标准安装脚本:(推荐 优点全面 缺点慢一点)
1 | /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" |
苹果电脑极速安装脚本:(优点安装速度快 缺点update功能需要命令修复 )
1 | /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" speed |
Linux 标准安装脚本:
1 | rm Homebrew.sh ; wget https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh ; bash Homebrew.sh |
苹果电脑卸载脚本:
1 | /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)" |
Linux卸载脚本:
1 | rm HomebrewUninstall.sh ; wget https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh ; bash HomebrewUninstall.sh |
删除 .DS_Store
删除当前目录及其子目录下的所有.DS_Store 文件:
1 | find . -name '*.DS_Store' -type f -delete |
禁止.DS_store生成:
1 | defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE |
恢复.DS_store生成:
1 | defaults delete com.apple.desktopservices DSDontWriteNetworkStores |
将 .DS_Store 加入到 .gitignore
1 | echo .DS_Store >> ~/.gitignore |
Python 镜像
1 | 清华大学镜像:https://pypi.tuna.tsinghua.edu.cn/simple/ |
Dev-Util
Google Maps API
网址 | 功能说明 | |
---|---|---|
1 | https://snazzymaps.com/ | 带有 JSON 代码和可下载示例的 Google 地图配色方案的存储库 |
2 | https://googlemapsmania.blogspot.com/search/label/Styled%20Maps | |
3 | https://mapstyle.withgoogle.com/ |
数据可视化
来源:“凯度信息之美奖”(The Kantar Information is Beautiful Awards)
- 最佳信息之美奖(Most Beautiful)-《天空中的密探》-作者:Peter Aldous 和 Charles Sefie(美国)
美国政府的空中监视行为截止到目前几乎不为人知。BuzzFeed News通过分析从航班追踪网站Flightradar24上得到的大约200架已辨别的联邦飞机位置数据,通过动态化的地图和路线图,借助VR技术形成了一幅前所未有的美国政府监视行动规模图景,为大家清晰展现一个政府监视下的美国。
- 数据可视化项目(Dataviz Project)金奖作品 -《数据美食》 - 作者:Moritz Stefaner和Susanne Jaschko(德国)
(在伊朗,一半全球前500的网站被封禁,但是70%的年轻网络用户试用代理服务器访问这些网站。该图用意大利调味饭中不同颜色的米粒代表这些数据。其中上半部分的黄色米粒代表可访问的网站,下半部分代表被封禁的网站,下半部分的黄色米粒代表通过代理服务器进行访问的网站)
食物可以作为展示数据的工具吗?数据是什么味道?
数据美食工作坊将美食作为一种工具来展示数据。该工作坊由德国艺术设计网站Prozessagenten发起,由数据可视化专家Moritz Stefaner负责艺术设计。该工作坊会采用当地的食物来展示当地相关的数据,比如说用当地鱼类做的鱼汤来展示当地渔业的数据,用披萨来展示芬兰首都赫尔辛基的不同种族人口比率等。
- 交互可视化类(Interactive)金奖作品《航运地图》 - 作者:Robin Houston 和 Duncan Clark(英国)
基于2012全年全球商业航运数据的交互式3D地图,展示了现代商业航运的巨大规模,大型商船的航运路线,不同类型商船的地理分布和它们的碳排放量。这幅地图以动画片的形式呈现,在缓缓的音乐中还伴随着关于对商业航运的重要性、运输货物的重要河流及地区等的讲解。
- 数据可视化网站(Dataviz Website)金奖作品《流动的数据》作者:Nathan Yau(邱南森)
Flowingdata.com网站由数据统计师Nathan Yau运营,持续更新原创或整合的数据可视化内容。该网站上现在有大量的数据可视化作品、数据可视化学习教程和指南等。
- 商业项目(Commercial/biz Project)金奖作品《数据美国》
该网站由德勤(Deloitte)、Datawheel数据公司和麻省理工学院媒体实验室Macro Connections共同创建。数据美国是一个开放的免费资源平台,提供美国政府多家统计部门的官方数据,现有180多万个数据可视化成果,范围涵盖工业、教育、职场等多个领域。
- 年度最佳工作室(Studio of the Year)- Polygraph工作室
Polygraph斩获了今年的“年度最佳工作室”奖。工作室研究的话题广泛,相比用文字枯燥的表述,他们更喜欢借助画面、符号等动态信息开展对不同课题的研究。代表作品为《对话电影》和《音乐品味的变革》。
- 《对话电影》探讨了性别、社会背景、票房数据等因素对于电影的影响。通过数据鲜明反映出了当今电影的多元化趋势。
- 《音乐品味的变革》通过研究1958年至2015年公告牌歌曲的排名变化,展现各个时代音乐的流行趋势。
- 最佳团队奖(Outstanding Team)FiveThirtyEight 网站
美国FiveThirtyEight网站团队获得此奖。该网站成立于2008年,特点是基于大量数据来预测新闻。最具代表性的作品便是通过棒球比赛数据成功预测出奥巴马将赢得美国总统大选。网站在不牺牲严密性和准确性的前提下,让数据新闻变得生动且通俗易懂,更加吸引读者。代表作品是《2016年美国大选预测》。话说小编很想知道这次特朗普当选FiveThirtyEight的预测是否靠谱啊。
- 最佳个人奖(Outstanding Individual)Moritz Stefaner(德国)- 天神项目——季风能源预测
天气预报的预测范围局限于未来几周,气候预报的预测范围放眼于未来几年。对于能源交易商来说,了解未来几个月的风况则最为重要。基于复杂的气候模型,该项目将尝试用新的方法预测未来几个月的风况,为风能基地提供帮助。
- 数据可视化项目(Dataviz Project)金奖作品《数据美食》- 作者:Moritz Stefaner和Susanne Jaschko(德国)
(在伊朗,一半全球前500的网站被封禁,但是70%的年轻网络用户试用代理服务器访问这些网站。该图用意大利调味饭中不同颜色的米粒代表这些数据。其中上半部分的黄色米粒代表可访问的网站,下半部分代表被封禁的网站,下半部分的黄色米粒代表通过代理服务器进行访问的网站)
食物可以作为展示数据的工具吗?数据是什么味道?
数据美食工作坊将美食作为一种工具来展示数据。该工作坊由德国艺术设计网站Prozessagenten发起,由数据可视化专家Moritz Stefaner负责艺术设计。该工作坊会采用当地的食物来展示当地相关的数据,比如说用当地鱼类做的鱼汤来展示当地渔业的数据,用披萨来展示芬兰首都赫尔辛基的不同种族人口比率等。
- 《洛杉矶及芝加哥的收入差距》 - 作者:Herwig Scherabon(美国)
作者通过两张大图将洛杉矶和芝加哥的收入差距可视化。图中两座城市的矩形建筑物高度对应了每个区域的收入水平,清晰地展现了现代城市中的贫富差距。文中指出,大多数情况下,收入分化与种族隔离相关,暗指城市规划背后的政治操控。
Tornado 试用思考
Tornado 在物联网上结合 twisted 蛮好用的。tornado 主要用于 websocket/tcp 这些长连接数据流的场景,结合 async 很有效,python 生态里暂时应该没有更好的替代框架。tornado支持把底层事件循环换成 asyncio 的循环。接着 gevent 还可以把 asyncio 的循环再 patch掉。这样 tornado 可以轻松异步调用任何支持 asyncio 或 gevent 的库。同时在 Windows 上使用 gevent (IOCP) 的 tornado 会有非常恐怖的并发能力。如果供 web CRUD 或者 restful 接口设计,优势不大。几个主流 python 框架更多是互补关系,不是竞争关系。
Duplicate Refresh of FetchRequest in the Sheet Detents Change
Sheet detent 改变的时候 Fetchrequest 都会被重新请求一次。这样在用户频繁的 sheet 交互中会造成严重的性能问题
- Debounce 输入防抖处理:防止用户快速输入时频繁触发后台任务。使用 Combine 的 .debounce 方法来减少频繁的输入请求,这样只有在用户停止输入一定时间后才会触发搜索操作,减少不必要的后台任务。DispatchQueue 或 Combine 可以用于实现此功能。
- 防止不必要的刷新:每次 sheet detent 改变时导致 FetchRequest 重新刷新,可能是因为 SwiftUI 在某些条件下会重新计算视图。如果 FetchRequest 在视图中定义,视图重新计算时会重新发起查询。我们可以考虑将 FetchRequest 与 View 逻辑分离,使用 @ObservedObject 或 @StateObject 来持久化状态,利用 @ObservedObject 或 @StateObject 来创建和管理一个 ViewModel,将数据获取逻辑从视图中分离出来,这样可以更好地控制数据的刷新逻辑,并且在 View 重新计算时不会重新发起请求,避免 FetchRequest 在视图生命周期中的自动刷新。
JVM Reflection
JVM为每个加载的class
及interface
创建了对应的Class
实例来保存class
及interface
的所有信息;
获取一个class
对应的Class
实例后,就可以获取该class
的所有信息;
通过Class实例获取class
信息的方法称为反射(Reflection);
JVM总是动态加载class
,可以在运行期根据条件来控制加载class。
Binding get 和 set 实现对任意数据源的双向绑定
闭包(closures)在编程中有许多重要作用,尤其在 Swift 语言中,它们提供了强大的功能和灵活性。以下是闭包的主要作用和适用场景:
1. 匿名函数:闭包允许你创建没有名字的内联函数,用于临时任务或一次性操作。
2. 捕获和存储状态:闭包可以捕获其上下文中的变量,并在以后使用这些变量,即使变量的原始作用域已经销毁。
3. 回调和异步操作:闭包常用于回调函数中,处理异步操作的结果,例如网络请求、动画完成处理等。
4. 函数作为参数和返回值:闭包可以作为参数传递给函数,也可以作为函数的返回值,从而实现高阶函数和函数式编程。
5. 简化代码和提高可读性:在许多情况下,闭包可以使代码更简洁和更具可读性,尤其是在处理集合、排序和过滤时。
适用场景
1. 回调函数
回调函数是闭包最常见的使用场景之一。它们允许你在某个操作完成后执行特定的代码,例如网络请求完成后处理响应数据。
1 | func fetchData(completion: @escaping (Data?, Error?) -> Void) { |
2. 处理集合
闭包用于 Swift 的标准库方法,如 map、filter 和 reduce,可以简化集合的处理。
1 | let numbers = [1, 2, 3, 4, 5] |
3. 排序
闭包用于定义自定义的排序逻辑。
1 | let names = ["Charlie", "Alice", "Bob"] |
4. 动画和视图更新
闭包常用于动画的开始和结束处理,以及视图的状态更新。
1 | UIView.animate(withDuration: 0.5, animations: { |
5. 自定义操作
闭包允许你在某些操作中传递自定义的行为,例如自定义操作的实现。
1 | func performOperation(_ operation: (Int, Int) -> Int, on a: Int, and b: Int) -> Int { |
6. 延迟执行
闭包用于延迟执行代码,直到某个条件满足或某个事件发生。
1 | func delay(seconds: Double, completion: @escaping () -> Void) { |