Gowhich

Durban's Blog

很多新手在进行macOS app开发的时候
创建完项目后一般会遇到一个问题,就是我连swift都没有学过,或者我只是接触过语法,那么看到下面这个ContentView.swift文件的代码的时候,代码如下

1
2
3
4
5
6
7
8
9
10
11
12
struct ContentView: View {
@State var name: String = "durban"
var body: some View {
Text("Hello, World").frame(maxWidth: .infinity, maxHeight: .infinity)
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

可能完全迷糊

如果是从object-c转过来了的,看到这个可能也比较迷糊,比如我

一般正常的可能认为
应该有个controller结尾的文件,跟我们使用Object-c开发项目的逻辑一样

其实实际上则不然

通过对swift项目的初步接触
我了解到一个struct的不同之处
可以说是与class类似的一个特殊使用方法

这里引用官网的说明

Structures and classes in Swift have many things in common. Both can:

  • Define properties to store values
  • Define methods to provide functionality
  • Define subscripts to provide access to their values using subscript syntax
  • Define initializers to set up their initial state
  • Be extended to expand their functionality beyond a default implementation
  • Conform to protocols to provide standard functionality of a certain kind

For more information, see Properties, Methods, Subscripts, Initialization, Extensions, and Protocols.

Classes have additional capabilities that structures don’t have:

  • Inheritance enables one class to inherit the characteristics of another.
  • Type casting enables you to check and interpret the type of a class instance at runtime.
  • Deinitializers enable an instance of a class to free up any resources it has assigned.
  • Reference counting allows more than one reference to a class instance.

For more information, see Inheritance, Type Casting, Deinitialization, and Automatic Reference Counting.

The additional capabilities that classes support come at the cost of increased complexity. As a general guideline, prefer structures because they’re easier to reason about, and use classes when they’re appropriate or necessary. In practice, this means most of the custom data types you define will be structures and enumerations. For a more detailed comparison, see Choosing Between Structures and Classes.

原文访问地址点这里

我认为读懂此部分相当重要

swift基础知识,掌握swift的版本号如何查看,swift文档权威官网

学习一门语言,我觉得应该掌握,这门语言的版本号,因为不同的版本号,导致网上的资料真假难以分别,只有掌握了,语言的版本号,才好去跟对方说我的问题是什么原因,才好去找对方或者去网上查找相关资料然后更加准确的定位问题

如何查看Xcode所使用Swift的版本

查看Swift版本

1
xcrun swift -version

查看Swift位置

1
xcrun --find swift

xcrun是xcode工具链中的其中一个

详细的xcode工具链可以参考这篇文章

swift 官网文档

官网地址:https://swift.org/

swift翻译版本地址:https://github.com/SwiftGGTeam/the-swift-programming-language-in-chinese

同时附带了术语表

SwiftUI Tutorials

这部分有详细的针对SwiftUI的讲解说明,对于新手入门很有用

地址请点击这里

eui_skins文件夹外eui文件不加载的怎么处理

修改egretProperties.json配置文件(关闭Egret UI Editor的情况下)

加入如下配置

1
2
3
4
5
6
7
8
9
10
"eui": {
"exmlRoot": [
"resource/eui_skins",
"resource/scene"
],
"themes": [
"resource/default.thm.json"
],
"exmlPublishPolicy": "commomjs"
},

默认配置是没有这个选项的

Laravel - Spark 10.1.0 版本发布

Spark 10.1.0 版本发布,兼容 Laravel 安全版本

Spark 10.1.0 has been released with compatibility for this week’s Laravel security release.

这里的Spark是什么

第一次看到,我也不知道,于是百度了下

Spark 原文地址 https://spark.laravel.com/docs/10.0/quickstart

Spark提供了您开始开发下一个大创意所需的所有脚手架。

开箱即用包括身份验证,API令牌和身份验证,订阅计费,付款方式更新,发票,密码重置等。

Spark provides all of the scaffolding you need to get started developing your next big idea. Authentication, API tokens and authentication, subscription billing, payment method updates, invoicing, password reset, and more is included out of the box.

在linux下设置密码复杂度办法:

(1)修改/etc/login.defs文件

1
2
3
4
PASS_MAX_DAYS   90  #密码最长过期天数
PASS_MIN_DAYS 80 #密码最小过期天数
PASS_MIN_LEN 10 #密码最小长度
PASS_WARN_AGE 7 #密码过期警告天数

(2)修改/etc/pam.d/system-auth文件

找到 password requisite pam_cracklib.so 这么一行替换成如下(如果没有的话自己添加下):

1
password requisite pam_cracklib.so retry=5 difok=3 minlen=10 ucredit=-1 lcredit=-3 dcredit=-3 dictpath=/usr/share/cracklib/pw_dict

参数含义(依次如下):

尝试次数:5
最少不同字符:3
最小密码长度:10
最少大写字母:1
最少小写字母:3
最少数字:3
密码字典:/usr/share/cracklib/pw_dict

cracklib密码强度检测过程:

  1. 首先检查密码是否是字典的一部分,如果不是,则进行下面的检查
  2. 密码强度检测过程
  3. 新密码是否旧密码的回文
  4. 新密码是否只是就密码改变了大小写
  5. 新密码是否和旧密码很相似
  6. 新密码是否太短
  7. 新密码的字符是否是旧密码字符的一个循环 例如旧密码:123 新密码:231
  8. 这个密码以前是否使用过。

发布时间:Jul, 27 2020

**发布作者:**Taylor Otwell(Creator of Laravel)

发布了适用于Laravel 6.x和7.x版本的安全补丁。

这些版本已作为Laravel 6.18.29和7.22.2发布。

建议所有Laravel用户尽快升级到这些版本。

同时

升级到这些版本将使应用程序发布的所有现有cookie无效;因此,使用应用程序的用户将需要重新认证。

Update: Passport 9.3.2 has been released in order to provide compatibility with this security release.

原文地址:https://blog.laravel.com/security-release-laravel-61827-7220

redis持久化方式

第一种方式:快照

快照是默认的持久化方式。这种方式是就是将内存中数据以快照的方式写入到二进制文件中,默认的文件名为dump.rdb。

可以通过配置设置自动做快照持久化的方式。我们可以配置 redis在 n 秒内如果超过 m 个 key 被修改就自动做快照,下面是默认的快照保存配置:

  • save 900 1 #900 秒内如果超过 1 个 key 被修改,则发起快照保存
  • save 300 10 #300 秒内容如超过 10 个 key 被修改,则发起快照保存
  • save 60 10000

快照保存过程

  1. redis 调用 fork,现在有了子进程和父进程。
  2. 父进程继续处理 client 请求,子进程负责将内存内容写入到临时文件。由于 os 的实时复制机制( copy on write)父子进程会共享相同的物理页面,当父进程处理写请求时 os 会为父进程要修改的页面创建副本,而不是写共享的页面。所以子进程地址空间内的数据是 fork时刻整个数据库的一个快照。
  3. 当子进程将快照写入临时文件完毕后,用临时文件替换原来的快照文件,然后子进程退出。client 也可以使用 save 或者 bgsave 命令通知 redis 做一次快照持久化。 save 操作是在主线程中保存快照的,由于 redis 是用一个主线程来处理所有 client 的请求,这种方式会阻塞所有client 请求。所以不推荐使用。另一点需要注意的是,每次快照持久化都是将内存数据完整写入到磁盘一次,并不是增量的只同步变更数据。如果数据量大的话,而且写操作比较多,必然会引起大量的磁盘 io 操作,可能会严重影响性能。

第一种方式:aof

由于快照方式是在一定间隔时间做一次的,所以如果 redis 意外 down 掉的话,就会丢失最后一次快照后的所有修改。如果应用要求不能丢失任何修改的话,可以采用 aof 持久化方式。
aof 比快照方式有更好的持久化性,是由于在使用 aof 持久化方式时,redis 会将每一个收到的写命令都通过 write 函数追加到文件中(默认是 appendonly.aof)。当 redis 重启时会通过重新执行文件中保存的写命令来在内存中重建整个数据库的内容。
当然由于 os 会在内核中缓存 write 做的修改,所以可能不是立即写到磁盘上。这样 aof 方式的持久化也还是有可能会丢失部分修改。不过我们可以通过配置文件告诉 redis 我们想要通过 fsync 函数强制 os 写入到磁盘的时机。有三种方式如下(默认是:每秒 fsync 一次)

  • appendonly yes // 启用 aof 持久化方式
  • appendfsync always // 收到写命令就立即写入磁盘,最慢,但是保证完全的持久化
  • appendfsync everysec // 每秒钟写入磁盘一次,在性能和持久化方面做了很好的折中
  • appendfsync no // 完全依赖 os,性能最好,持久化没保证

aof 的方式也同时带来了另一个问题。持久化文件会变的越来越大。例如我们调用 incr test命令 100 次,文件中必须保存全部的 100 条命令,其实有 99 条都是多余的。因为要恢复数据库的状态其实文件中保存一条 set test 100 就够了。为了压缩 aof 的持久化文件。 redis 提供了 bgrewriteaof 命令。收到此命令 redis 将使用与快照类似的方式将内存中的数据以命令的方式保存到临时文件中,最后替换原来的文件。

原理使用css的伪类’:before’和’:after’

如果想要光标在内容的后面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
.class:before {
content: ''
}

.class:after {
content: '';
border-right: 2px solid #ffd500;
height: 50%;
opacity: 1;
animation: focus .7s forwards infinite;
}

@keyframes focus {
from {
opacity: 1;
}

to {
opacity: 0;
}
}

如果想要光标在内容的前面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
.class:before {
content: ''
border-right: 2px solid #ffd500;
height: 50%;
opacity: 1;
animation: focus .7s forwards infinite;
}

.class:after {
content: '';
}

@keyframes focus {
from {
opacity: 1;
}

to {
opacity: 0;
}
}

首先引入我们需要的Validator类

1
use Illuminate\Support\Facades\Validator;

举个简单的例子

比如要验证密码的安全性

我们可以这样写代码

1
2
3
4
5
6
7
8
9
10
11
12
13
public function index (Request $request) {
$validate = Validator::make($request->all(), [
'password' => [
'required',
'min:8',
'regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X])(?=.*[!$#%]).*$/',
],
]);

if ($validate->fails) {
\Log::info($validate->messages()->toJson());
}
}

如果像对验证的错误信息进行自定义

可以这样写代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public function index (Request $request) {
$validate = Validator::make($request->all(), [
'password' => [
'required',
'min:8',
'regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X])(?=.*[!$#%]).*$/',
],
], [
'password.min' => '密码格式长度错误',
'password.regex' => '密码格式错误',
]);

if ($validate->fails) {
\Log::info($validate->messages()->toJson());
}
}

Node v12.18.3 (LTS) 版本发布

发布时间:by Shelley Vohr, 2020-07-22

Notable Changes

  • deps:
    • upgrade npm to 6.14.6 (claudiahdz) #34246
    • update node-inspect to v2.0.0 (Jan Krems) #33447
    • uvwasi: cherry-pick 9e75217 (Colin Ihrig) #33521
0%