打包保护你的 Python 程序

1. 编译成可执行文件 可以使用工具将 Python 脚本转换为独立的可执行文件: 工具: PyInstaller: 支持多平台(Windows、macOS 和 Linux)。 pyinstaller –onefile your_script.py 上述命令会生成一个单独的可执行文件,位于 dist/ 目录下。 cx_Freeze: 也是一个常用的工具,支持类似功能。 cxfreeze your_script.py –target-dir dist/ py2exe(Windows 专用): 将 Python 脚本编译成 Windows 下的可执行文件。 优点: 生成的可执行文件不需要 Python 环境即可运行。 部分情况下可以混淆或隐藏源代码。 缺点: 用专业的反编译工具可能仍然还原部分代码逻辑。 2. 字节码保护 Python 源代码在运行时会被编译成字节码文件(.pyc),可以通过生成 .pyc 文件分发代码: 使用 compileall 模块生成字节码文件: python -m compileall your_script.py 然后分发生成的 .pyc 文件。 配合工具如 cython 或 […] →Read more

提高效率的 @EnableJdbcAuditing

@EnableJdbcAuditing 是 Spring Data JDBC 提供的一个注解,用于启用审计功能(Auditing)。它主要负责自动填充实体类中的审计字段,比如 createdBy、createdDate、lastModifiedBy 和 lastModifiedDate。 以下从功能、实现逻辑和源码解析三个方面详细说明。 1. 功能 @EnableJdbcAuditing 提供以下功能: 自动填充创建和修改时间:在插入或更新记录时,自动填充实体类中的时间字段(如 createdDate 和 lastModifiedDate)。 支持用户信息:可以自动填充创建者和修改者信息(如 createdBy 和 lastModifiedBy),需要配合自定义 AuditorAware 实现。 2. 使用示例 数据库表 假设有一张用户表 user: CREATE TABLE user ( id BIGINT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50), created_by VARCHAR(50), created_date TIMESTAMP, last_modified_by VARCHAR(50), last_modified_date TIMESTAMP ); 实体类 定义对应的实体类,标注审计字段: import org.springframework.data.annotation.CreatedBy; import org.springframework.data.annotation.CreatedDate; […] →Read more

Agile Testing Quadrants

四个维度 面向业务 面向技术 指导开发 指导产品 理想情况下, 我们希望以下 3 个象限是自动化的 Q1. 功能性验收测试 Q3. 单元/集成/系统测试 Q4. 非功能性验收测试(性能,压力,安全测试) →Read more

DNS-F

DNS-F (DNS Failover) is a DNS-based mechanism supported by Nacos, a dynamic service discovery and configuration management platform, to provide failover support for service discovery. It works by allowing services to use DNS queries to retrieve IP addresses of available service instances, ensuring resilience and reliability when instances become unavailable. Here’s a breakdown of what […] →Read more

The new and revised 15 factors

12 factor In the modern era, software is commonly delivered as a service: called web apps, or software-as-a-service. The twelve-factor app is a methodology for building software-as-a-service apps that: Use declarative formats for setup automation, to minimize time and cost for new developers joining the project; Have a clean contract with the underlying operating system, […] →Read more

RAG Architecture

A typical RAG application has two main components: Indexing: a pipeline for ingesting data from a source and indexing it. This usually happens offline. Retrieval and generation: the actual RAG chain, which takes the user query at run time and retrieves the relevant data from the index, then passes that to the model. The most […] →Read more

EnableAutoConfiguration 注解的原理

在 Spring Boot 中,@EnableAutoConfiguration 是一个核心注解,它实现了自动配置的功能。它的作用是根据项目中依赖的库以及应用上下文中的配置,自动配置 Spring 应用程序的上下文。以下是它的原理和运行机制: 1. @EnableAutoConfiguration 的定义 @EnableAutoConfiguration 注解本质上是一个复合注解,其源码如下: @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @AutoConfigurationPackage @Import(AutoConfigurationImportSelector.class) public @interface EnableAutoConfiguration { Class<?>[] exclude() default {}; String[] excludeName() default {}; } 主要包括以下两部分: • @AutoConfigurationPackage: 自动将当前类所在包及其子包中的所有组件注册到 Spring 容器。 • @Import(AutoConfigurationImportSelector.class): 导入了 AutoConfigurationImportSelector,用来加载所有可用的自动配置类。 2. 自动配置的核心机制 2.1 自动配置类的定义 自动配置类通过 spring.factories 文件定义,这个文件通常位于 META-INF 目录下。例如: org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration,\ org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration • 每个类都是一个自动配置类,Spring […] →Read more

Cloud Native

Cloud native practices empower organizations to develop, build, and deploy workloads in computing environments (public, private, hybrid cloud) to meet their organizational needs at scale in a programmatic and repeatable manner. It is characterized by loosely coupled systems that interoperate in a manner that is secure, resilient, manageable, sustainable, and observable. Cloud native technologies and […] →Read more

we live by an invisible sun within us

Life is a pure flame, and we live by an invisible sun within us 生命是一团纯净的火焰, 我们依靠自己内心看不见的太阳而生存 The vast, th unbounded prospect lies before us. →Read more

mybatis spring boot starter 是怎么做的

Overview 要与 Spring 一起使用 MyBatis,你至少需要一个 SqlSessionFactory 和一个 mapper 接口。 MyBatis-Spring-Boot-Starter 将会: 自动探测存在的 DataSource 将使用 SqlSessionFactoryBean 创建并注册一个 SqlSessionFactory 的实例,并将探测到的 DataSource 作为数据源 将创建并注册一个从 SqlSessionFactory 中得到的 SqlSessionTemplate 的实例 自动扫描你的 mapper,将它们与 SqlSessionTemplate 相关联,并将它们注册到Spring 的环境(context)中去,这样它们就可以被注入到你的 bean 中 MyBatis-Spring-Boot-Starter 是一个开箱即用的解决方案,用于将 MyBatis 与 Spring Boot 集成。它简化了 MyBatis 的配置和使用,同时充分利用了 Spring 的依赖注入和生命周期管理功能。以下是它的实现原理的详细解析: 自动配置的实现 MyBatis-Spring-Boot-Starter 利用了 Spring Boot 的自动配置机制,通过 @EnableAutoConfiguration 和 spring.factories 文件实现自动化配置。 spring.factories MyBatis-Spring-Boot-Starter […] →Read more