Spring Cloud Alibaba 集成 Spring Cloud

Spring Cloud Alibaba 集成 Spring Cloud 需要匹配对应的版本号,可以从以下链接进行匹配:

https://docs.spring.io/spring-cloud/docs/2021.0.x/reference/html/
https://github.com/alibaba/spring-cloud-alibaba/tree/2021.x
https://github.com/alibaba/spring-cloud-alibaba/releases/tag/2021.0.1.0

首先查看 Spring Cloud Alibaba 支持的 Spring Cloud 的版本号,然后从 Spring Cloud Alibaba release 页面的标注支持的详细中间件的版本号。

在 shell 中实现 urlencode 编码

在shell中实现 urlencode编码

在shell中进行urlencode编码有两种方式,一种是通过 curl,另外一种是通过 xxd 来达成结果,经实测使用 curl 来进行urlencode的编码效率更高。以下是两种实现方式:

使用 curl 进行 urlencode编码

脚本首先使用 which 检测 curl 是否已经安装,如果未安装将会编码失败并直接返回传入的参数
function urlencode() {
  which "curl" >/dev/null 2>&1; if [ ! $? -eq 0 ]; then echo -E "$1";return; fi
  encode_str=$(echo -E "$1" |sed "s/%/%%/g")
  printf -- "$encode_str" | curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "" |cut -c 3-
}

将上方的方法直接复制到shell脚本中,然后使用如下方式调用即可:

这只是 urlencode 方法的一个使用示例
send_text=$(urlencode "$text")

这样传入的 $text 会被编码,然后就可以拼接到请求链接中了。不会有任何问题,请求链接的时候使用 $send_text

然后使用 curl 在访问链接的时候,拼接参数即可:

# 拼接到请求的路径中
curl http://example.com/$send_text
 
# 拼接到请求的参数中
curl http://example.com?param=$send_text

这样就不会遇到特殊字符导致请求失败,或参数传递失败的问题了。

Bash shell 的 urlencode() / urldecode()

function urlencode() {
    local length="${#1}"
    for (( i = 0; i < length; i++ )); do
        local c="${1:i:1}"
        case $c in
            [a-zA-Z0-9.~_-]) printf "$c" ;;
            *) printf "$c" | xxd -p -c1 | while read x;do printf "%%%s" "$x";done
        esac
    done
}
function urldecode() {
    # urldecode <string>

    local url_encoded="${1//+/ }"
    printf '%b' "${url_encoded//%/\\x}"
}

Link:

去除iOS 项目中第三方库警告几种方式

去除全部第三方库的警告

在Podfile 文件前添加以下代码去除所有第三方库的警告

inhibit_all_warnings!

去除指定第三方库的警告

在指定Pod 后添加以下代码去除指定第三方库的警告

:inhibit_warnings => false

// 以下为参考代码
// pod 'LocalPod', :path => '../LocalPod', :inhibit_warnings => false

通过代码有条件去除第三方库的警告

pre_install do |installer|
  installer.analysis_result.specs_by_target.each_key do |target_definition|
    installer.analysis_result.specifications.each do |spec|
      source = spec.attributes_hash['source']
      source &&= source['git']
      next unless source && source.include?('cocoapods-repos')

      targets = (Array(target_definition) + target_definition.children)
      targets.each do |target|
        target.set_inhibit_warnings_for_pod(spec.root.name, true)
      end
    end
  end
end

// `source` 为 `Third.podspec` 中配置的 `s.source` ,可以根据自己的项目情况进行修改

Link:

Sourcetree 提示 "由于文件大小或模式问题无法进行差异对比" 的处理

今天实用SourceTree 对 .pbxproj 进行比对时,无法进行比对,提示 由于文件大小或模式问题无法进行差异对比。打开 偏好设置 看到文本文件限制大小为 1024kb ,想着 .pbxproj 文件应该增大到了无法进行比对了,于是将文件限制改为 2048kb ,返回切换下文件,文件比对结果就显示出来了。

解决步骤

  • 在提示的下方点击"偏好设置",或者直接进入 Sourcetree 的偏好设置,找到如下位置:

Sourcetree 偏好设置

  • 然后将大小限制(文本)改为比你的文件更大的即可,对我来讲这里我改成2048就可以了,我要对比的是 .pbxproj 文件
  • 更改完成之后可能不会立马看到效果,这时候切换一下已经发生变更的其他文件,然后再切回之前无法查看差异的文件即可.或者重启Sourcetree

Link:

  • [Sourcetree "由于文件大小或模式问题无法进行差异对比"](

使用子控制器分解复杂模块页面功能

我们在开发的过程中,通常会对复杂界面进行分模块处理,降低页面的复杂度,提高代码的可维护性。使用子控制器是一个很好的主意。

使用子控制器有以下好处:

1.无疑,对页面中的逻辑更加分明了。相应的View对应相应的ViewController。
2.当某个子View没有显示时,将不会被Load,减少了内存的使用。
3.当内存紧张时,没有Load的View将被首先释放,优化了程序的内存释放机制

使用方法:

  • addChildViewController:的同时调用addSubView:
[self addChildViewController:sfViewControllr];
[self.view addSubview:sfViewControllr.view];
  • 设置子视图的位置,并显示出来
sfViewControllr.view.frame = CGRectMake(0, 300, 1, 1);
[sfViewControllr didMoveToParentViewController:self];
  • 移除子视图
[sfViewControllr willMoveToParentViewController:nil];
[sfViewControllr removeFromParentViewController];
[sfViewControllr.view removeFromSuperview];

可能遇到的问题:
如果在子Controller中,把自己从父Controller中移除,在ios6中没问题,在iOS7中,会崩溃

[self willMoveToParentViewController:nil];
[self.view removeFromSuperview];
[self removeFromParentViewController]; //ios7中崩溃

暂时的解决方法,在子Controller中发通知,通知父Controller,移除子Controller

Link:

CocoaPods使用代理

更改gem源

这里的 https://rubygems.org/ 可以不进行变动,前提是你代理方能够访问的话,就可以跳过变更 gem

gem sources -l
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com
gensees-iMac:~ gensee$ gem sources -l
*** CURRENT SOURCES ***

https://rubygems.org/
https://gems.ruby-china.com
gensees-iMac:~ gensee$ gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
gensees-iMac:~ gensee$ gem sources --add https://gems.ruby-china.com
source https://gems.ruby-china.com already present in the cache
gensees-iMac:~ gensee$

由于gem源有可能变动,这里去 https://gems.ruby-china.com 查看最新即可

设置代理端口

设置代理

这里的设置是全局的
//端口号可以自己更改
git config --global http.proxy 'socks5://127.0.0.1:7890'
git config --global https.proxy 'socks5://127.0.0.1:7890'
//一般来说设置前两个就行了
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

这里的127.0.0.1代表本机地址,然后端口是7890,如果使用SS的同学,需要查看配置,端口号可以自己更改

代理配置

这里必须一致才行

查看代理

git config --global --get http.proxy
git config --global --get https.proxy

取消方法

#取消
git config --global --unset http.proxy
git config --global --unset https.proxy

验证

这里使用git clone指令验证

gensees-iMac:git gensee$ git clone https://github.com/AFNetworking/AFNetworking.git
Cloning into 'AFNetworking'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (2/2), done.
Receiving objects:  21% (3339/15468), 796.01 KiB | 514.00 KiB/s    

这里就可以看到下载速度了,如果你的速度还是10几K,那就看看是不是没有设置成功呢,例如没有开启BBR,没开BBR是很慢的。

然后,你就可以用 pod install 什么的指令了,起飞吧

Link:

加快 Homebrew 安装软件速度

我们在 Mac 上使用 brew 命令软件是一个非常方便的操作,媲美 Ubuntu 上 apt 命令。但在国内使用该命令安装软件的速度却十分感人,所以我们需要使用一些科学的方式来进行提速。

Homebrew 安装软件是通过 git clone 命令来下载软件,然后再进行安装,知道原理后我们就可以通过提高 git clone 命令的速度来提升软件安装的速度。

使用以下命令来提高 git clone 命令的速度:

//端口号可以自己更改
git config --global http.proxy 'socks5://127.0.0.1:7890'
git config --global https.proxy 'socks5://127.0.0.1:7890'
//一般来说设置前两个就行了
git config --global https.proxy http://127.0.0.1:7890
git config --global https.proxy https://127.0.0.1:7890

这里的127.0.0.1代表本机地址,然后端口是1080,如果使用SS的同学,需要查看配置,端口号可以自己更改

查看代理

git config --global --get http.proxy
git config --global --get https.proxy

取消代理

git config --global --unset http.proxy
git config --global --unset https.proxy

设置完成后,我们可以通过 git clone 命令来验证下速度,如果速度还是跟原来一样,需要检查下设置是否正确。

Link:

Mac 安装 Homebrew

Mac 安装 Homebrew 很简单,只需要一行命令,就可以拥有媲美 Ubuntu 下的 apt 命令工具:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

更新 Homebrew:

brew update
PS:最好先设置代理再进行安装,不然安装速度会让你怀疑人生