Algorithm

Leetcode 1 两数之和

给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 的那 两个 整数,并返回它们的数组下标。
示例 1:
输入:nums = [2,7,11,15], target = 9
输出:[0,1]
解释:因为 nums[0] + nums[1] == 9 ,返回 [0, 1] 。

示例 2:
输入:nums = [3,2,4], target = 6
输出:[1,2]

示例 3:
输入:nums = [3,3], target = 6
输出:[0,1]

方法一:暴力解法

  1. /**
  2. * @param {number[]} nums
  3. * @param {number} target
  4. * @return {number[]}
  5. */
  6. var twoSum = function(nums, target) {
  7. var len=nums.length;
  8. for (var i=0; i<len; i++){
  9. for (var j=0; j<len; j++)
  10. if (nums[i]+nums[j]==target & (i!=j)){
  11. return [i,j];
  12. }
  13. }
  14. };

image.png

方法二:一遍哈希表

  1. /**
  2. * @param {number[]} nums
  3. * @param {number} target
  4. * @return {number[]}
  5. */
  6. const twoSum = function(nums, target) {
  7. const len=nums.length;
  8. var numMaps=new Map();
  9. for (var i=0; i<len; i++){
  10. var complement=target-nums[i];
  11. if (numMaps.has(complement)){
  12. return [numMaps.get(complement),i];
  13. }
  14. numMaps.set(nums[i],i);
  15. }
  16. };

image.png

Review

How to become a blockchain developer

介绍了成为一个区块链开发者的必要知识和技能。

TOP BLOCKCHAIN PLATFORMS OF 2021

介绍了不同的区块链开发平台,发现了几个专门针对金融行业和数字资产的,但是他们的共识算法都不一样,分别是Pluggable Framework、Partionned Consensus、Stellar Consensus Protocol,就还挺奇怪的。以后有时间可以了解下区别。不过腾讯区块链云平台,底层用的是Linux基金会推出的超级账本,R3 Corda在共识协议方面看起来和它比较接近了。看了这几个公司的主页设计风格,最喜欢Stellar了。
超级账本竟然出了两个平台?表格里看不出FabricSawtooth有什么区别。


Ethereum
Hyperledger Fabric R3 Corda Ripple Quorum Hyperledger Sawtooth EOS Hyperledger Iroha OpenChain Stellar
Industry focus Cross-Industry Cross-Industry Financial Services Financial Services Cross-Industry Cross-Industry Cross-Industry Cross-Industry Digital Asset Management Financial Services
Ledger Type Permissionless Permissioned Permissioned Permissioned Permissioned Permissioned Permissioned Permissioned Permissioned Both Public & Private
Consensus Algorithm Proof of Work Pluggable Framework Pluggable Framework Probabilistic Voting Majority Voting Pluggable Framework Delegated Proof-of-Stake Chain-based Byzantine Fault Tolerant Partionned Consensus Stellar Consensus Protocol
Smart Contract Yes Yes Yes No No Yes Yes Yes Yes Yes
Governance Ethereum Developers Linux Foundation R3 Consortium Ripple Labs Ethereum Developers and JP Morgan Chase Linux Foundation EOSIO Core Arbitration Forum(ECAF) Linux Foundation CoinPrism Stellar Development Foundation


Technique/Tips

Swagger集成文档

“Spring Boot作为当前最流行的Java Web开发脚手架,被越来越多的开发者用来构建企业级Restful API接口,这些接口不但服务于传统的Web端,还会服务于移动端。这些接口还要给开发测试人员做白盒测试,因此存在多人协作中共享和及时更新API开发接口文档的问题。”Swagger2相比传统的WIKI存在更多优势。

集成MyBatis框架

“MyBatis是一款持久层框架,支持定制化SQL、存储过程以及高级映射。MyBatis可以使用简单的XML或注解来配置和映射原生信息,并将接口和Java的POJOs映射成数据库中的记录。

集成Druid数据源

“数据库连接池负责分配、管理和释放数据库连接。……Java应用程序开发中,常用的连接池有DBCP、C3P0、Proxool等。Spring Boot默认了几种连接池,默认数据源是org.apache.tomcat.jdbc.pool.DataSource。Druid是阿里系提供的一个连接池,还提供了数据库监控和扩展功能。”

CORS技术

为了解决浏览器跨域(请求地址里面的协议、域名和端口号不同)问题,W3C给出的解决方案,全名Cross-Origin Resource Sharing。

工程结构规划

“随着项目越来越大,代码的可重用性和可维护性会变得越来越难。所以尽早对工程结构进行合理规划,对项目前期的开发,后期的扩展和维护是非常重要的。”

  • -common公共模块,放置一些工具类
  • -core核心业务模块,封装公共业务
  • -admin后台管理模块,包含用户、角色、菜单管理
  • -pom聚合模块,仅为简化打包,一键执行打包所有模块

    登陆流程实现

    利用kaptcha实现登陆验证码,利用进行安全控制

    数据备份还原

    通过代码调用MySQL的备份还原命令实现系统还原

    系统服务监控

    使用Spring Boot Admin,可以在管理界面浏览所有被监控项目的基本信息(Health、内存、JVM、垃圾回收、配置信息)

    注册中心

    使用开源工具Consul, 用Go语言编写,用于实现分布式系统的服务发现与配置,与Docker等轻量级容器可无缝配合。

    服务消费

    微服务架构中,服务运行在各自的进程中,甚至部署在不同的主机、不同的地区。所以需要远程调用技术。Spring Cloud体系里比较广泛的调用方式有RestTemplate、Feign

    服务熔断(Hystrix、Turbine)

    熔断器类似于电力过载保护器,防止应用程序不断执行可能会失败的操作。通过记录最近调用发生错误的次数,来决定哪些操作继续,或者返回错误。

    服务网关(Zuul)

    统一向外系统提供REST API,具备服务路由、负载均衡、权限控制功能
    Spring Cloud Zuul

    链路追踪(Sleuth、ZipKin)

    Spring Cloud Sleuth
    使用Docker方式部署ZipKin服务

    配置中心(Config、Bus)

    Spring Cloud Config
    Spring Cloud Bus消息总线

    Share

    Cloud Native云原生的定义

    Definition:Cloud native technologies empower organizations to build and run scalable applications in modern, dynamic environments such as public, private, and hybrid clouds. Containers, service meshes服务网格, microservices微服务, immutable infrastructure不可变基础设施, and declarative APIs 声明式APIexemplify this approach.

“到了2018年,随着近几年来云原生生态的不断壮大,所有主流云计算供应商都加入了Google主导成立的云原生计算基金会(CNCF),且从Cloud Native Landscape中可以看出云原生有意蚕食原先非云原生应用的部分。”

These techniques enable loosely coupled systems松耦合系统 that are resilient有弹性的, manageable, and observable. Combined with robust automation可靠的自动化手段, they allow engineers to make high-impact changes frequently and predictably with minimal toil辛勤劳动.

The Cloud Native Computing Foundation seeks to drive adoption of this paradigm范式 by fostering and sustaining an ecosystem of open source, vendor-neutral厂商中立的 projects. We democratize state-of-the-art 民主化最前沿的 patterns to make these innovations accessible for everyone.