202406

Python One Billion Row Challenge — From 10 Minutes to 4 Seconds
https://archive.is/a644q

Processing One Billion Rows in PHP!
https://dev.to/realflowcontrol/processing-one-billion-rows-in-php-3eg0

mysql 中如下 json 字段

{
   "status": "OK",
   "results": [
      {
         "types": [
            "locality",
            "political"
         ],
         "place_id": "ChIJpdtYF6azhkcRmu5nCgU7BtM",
         "formatted_address": "20874 Busnago, Province of Monza and Brianza, Italy",
         "address_components": [
            {
               "types": [
                  "locality",
                  "political"
               ],
               "long_name": "Busnago",
               "short_name": "Busnago"
            },
            {
               "types": [
                  "administrative_area_level_3",
                  "political"
               ],
               "long_name": "Busnago",
               "short_name": "Busnago"
            },
            {
               "types": [
                  "administrative_area_level_2",
                  "political"
               ],
               "long_name": "Province of Monza and Brianza",
               "short_name": "MB"
            },
            {
               "types": [
                  "administrative_area_level_1",
                  "political"
               ],
               "long_name": "Lombardy",
               "short_name": "Lombardy"
            },
            {
               "types": [
                  "country",
                  "political"
               ],
               "long_name": "Italy",
               "short_name": "IT"
            },
            {
               "types": [
                  "postal_code"
               ],
               "long_name": "20874",
               "short_name": "20874"
            }
         ]
      }
   ]
}

要取 types 里包含 administrative_area_level_3 的上级节点的 long_name 值

select 
    country_code,
    location,response->>'$.results[0].formatted_address' formatted_address,
    json_unquote(
        json_extract(
            response,
            concat(
                '$.results[0]',
                REGEXP_REPLACE(
                    JSON_SEARCH(
                        response->>'$.results[0]',
                        'one', 
                        'administrative_area_level_1'
                    ),
                    '"|\\$|\\.types\\[[0-9]]',''
                ),
                '.long_name')
        )
    ) administrative_area_level_1 
from t limit 10;
  1. 先用 JSON_SEARCH 得到 administrative_area_level_1 的路径,类似 $.address_components[3].types[0]
  2. 用 REGEXP_REPLACE 替换掉前面的 $ 和最后的 .types[0]
  3. 用 concat 拼接所需的 json path,类似 $.results[0].address_components[2].long_name
  4. 用 json_extract 取出所需要的值
  5. 用 json_unquote 去掉结果两侧的引号

乱码替换

>>> re.sub(r'x(\w\d)x(\w\d)',lambda x: bytes.fromhex(x.group(1)+x.group(2)).decode('utf-8'),'Logrosxc3xa1n')
'Logrosán'
>>> re.sub(r'x(\w\d)x(\w\d)',lambda x: bytes.fromhex(x.group(1)+x.group(2)).decode('utf-8'),'Trxc3xa9mentines')
'Trémentines'
>>> re.sub(r'x(\w\d)x(\w\d)',lambda x: bytes.fromhex(x.group(1)+x.group(2)).decode('utf-8'),'Trxc3xa9lazxc3xa9')
'Trélazé'
>>> re.sub(r'x(\w\d)x(\w\d)',lambda x: bytes.fromhex(x.group(1)+x.group(2)).decode('utf-8'),'Jxc3xa4msxc3xa4nkoski')
'Jämsänkoski'
>>> re.sub(r'x(\w\d)x(\w\d)',lambda x: bytes.fromhex(x.group(1)+x.group(2)).decode('utf-8'),'Sxc3xb8llerxc3xb8d')
'Søllerød'
>>> re.sub(r'x([0-9a-fA-F]{1,2})x([0-9a-fA-F]{1,2})',lambda x: bytes.fromhex(x.group(1)+x.group(2)).decode('utf-8'),'Sxc3xb8llerxc3xb8d')

‘Søllerød’

手搓一个最小的 Agent 系统 — Tiny Agent
https://zhuanlan.zhihu.com/p/699732624

  • MetaGPT: 本质类似于公司的组织架构,横向同一层级的工作模式,可能是COT、TOT、GOT,纵向深度有不同的层级,如role、action、action node等
  • React: 就像是个不是特别聪明的孩子,要把想法写出来,然后去综合所有想法和观察,接着再做出相应的动作。
  • Reflexion: 一种“语言”强化的新范式,它将策略参数化为代理的记忆编码,并配对参数选择LLM。
  • Toolformer: 一种学习以新颖方式使用工具的模型,它通过自监督的方式学习如何使用不同的工具,如搜索引擎、计算器和翻译系统。
  • Swiftsage: 用一个小模型直接输出决策,当小模型不行时改用大模型通过复杂planning输出决策。
  • Creator: 通过工具创造实现了大模型抽象与具象思维能力的解耦,面对有难度的问题能够保持更好的鲁棒性。

OpenAI 不可用?使用开源模型一键替换 OpenAI API
https://mp.weixin.qq.com/s?__biz=MzI2MjkxNjA2Mg==&mid=2247487114&idx=1&sn=0c443a88bafa49daec18f8a16d0c6284

docker run --rm -p 8080:8080 --name api-server secondstate/llama-3-8b-nomic-1.5:latest

curl -X POST http://localhost:8080/v1/chat/completions \
    -H 'accept:application/json' \
    -H 'Content-Type: application/json' \
    -d '{"messages":[{"role":"system", "content": "You are a helpful assistant."}, {"role":"user", "content": "What is the capital of France?"}], "model": "Meta-Llama-3-8B-Instruct-Q5_K_M.gguf"}'

curl -X POST http://localhost:8080/v1/embeddings \
    -H 'accept:application/json' \
    -H 'Content-Type: application/json' \
    -d '{"model": "nomic-embed-text-v1.5.f16", "input":["LlamaEdge is the easiest & fastest way to run customized and fine-tuned LLMs locally or on the edge."]}'

https://www.secondstate.io/articles/wasm-runtime-agi/

长时间以来,来自开源生态的朋友们一致支持着Qwen的发展,包括

  • 微调(Axolotl、Llama-Factory、Firefly、Swift、XTuner)、
  • 量化(AutoGPTQ、AutoAWQ、Neural Compressor)、
  • 部署(vLLM、SGL、SkyPilot、TensorRT-LLM、OpenVino、TGI)、
  • 本地运行(MLX、Llama.cpp、Ollama、LM Studio)、
  • Agent及RAG(检索增强生成)框架(LlamaIndex, CrewAI, OpenDevin)、
  • 评测(LMSys, OpenCompass, Open LLM Leaderboard)、
  • 模型二次开发(Dolphin, Openbuddy)。

https://zhuanlan.zhihu.com/p/703883561

https://llamaedge.com/

Q: Why can’t I use Python to run the LLM inference?
A: You can certainly use Python to run LLMs and even start an API server using Python. But keep mind that PyTorch has over 5GB of complex dependencies. These dependencies often conflict with Python toolchains such as LangChain. It is often a nightmare to set up Python dependencies across dev and deployment machines, especially with GPUs and containers.

In contrast, the entire LlamaEdge runtime is less than 30MB. It is has no external dependencies. Just install LlamaEdge and copy over your compiled application file!

Q: Why can’t I just use native (C/C++ compiled) inference engines?
A: The biggest issue with native compiled apps is that they are not portable. You must rebuild and retest for each computer you deploy the application. It is a very tedious and error prone progress. LlamaEdge programs are written in Rust (soon JS) and compiled to Wasm. The Wasm app runs as fast as native apps, and is entirely portable.

wasm 使用案例
https://wasmedge.org/docs/zh/start/usage/use-cases/

阿里千问
https://qwen.readthedocs.io/en/latest/framework/LlamaIndex.html

  1. 本地安装,测试,部署很方便,支持多种方式,满足不同需求
  2. 量化,fine tune(有监督训练), embedding(RAG)都支持本地实现
  3. function call,Agent, LangChain相关功能需要使用阿里的dashscope服务

跨设备运行小小阿里云通义千问大模型 Qwen1.5-0.5B-Chat
https://zhuanlan.zhihu.com/p/684034037

mac如何安装git-lfs,以及modelscope的使用示例
https://zhuanlan.zhihu.com/p/692680970

ModelScope+transformers调用llama模型
https://zhuanlan.zhihu.com/p/698481268

https://zhuanlan.zhihu.com/p/681690385

https://wasmedge.org/docs/develop/rust/wasinn/llm_inference/

-m, --model-alias <ALIAS>
      Model alias [default: default]
-c, --ctx-size <CTX_SIZE>
      Size of the prompt context [default: 4096]
-n, --n-predict <N_PRDICT>
      Number of tokens to predict [default: 1024]
-g, --n-gpu-layers <N_GPU_LAYERS>
      Number of layers to run on the GPU [default: 100]
-b, --batch-size <BATCH_SIZE>
      Batch size for prompt processing [default: 4096]

苹果AppleMacOs系统Sonoma本地部署无内容审查(NSFW)大语言量化模型Causallm
https://zhuanlan.zhihu.com/p/686099177
https://hf-mirror.com/tastypear/CausalLM-7B-DPO-alpha-GGUF

LLaMA-Factory QuickStart
https://zhuanlan.zhihu.com/p/695287607

使用 Python库DEAP的多目标优化示例
https://blog.csdn.net/gongdiwudu/article/details/138033230

Pygmo multi-objective optimization with constraints
https://stackoverflow.com/questions/77411477/pygmo-multi-objective-optimization-with-constraints

命令行听歌

for %%i in (D:\mp3\*.mp3) do D:\haohu\soft\ffmpeg\bin\ffplay "%%i" -autoexit

基于STM32+VS1053B的MP3设计
https://zhuanlan.zhihu.com/p/690699207

这里我们使用的是stm32F103VET6,内部Flash有512K,100pin的外部引脚,属于大容量芯片,足够我们diy。对于本设计,stm32这一块用到的知识点有:SDIO驱动SD卡,SPI驱动VS1053B芯片,IIC驱动OLED;对于程序,用的是stm32标准库

功能范围:

  • CPU 专注于通用计算任务。
  • SoC 集成了多个功能模块,满足复杂的计算和通信需求。
  • MCU 专注于特定的嵌入式应用,如控制系统、传感器等。

应用领域:

  • CPU 广泛用于个人电脑、服务器等通用计算设备。
  • SoC 常见于智能手机、平板电脑等便携设备。
  • MCU 主要应用于嵌入式系统,如家电、汽车电子等。

集成程度:

  • CPU 通常作为计算机系统的核心,但需要其他芯片的支持。
  • SoC 在一个芯片上集成了多个功能模块。
  • MCU 是一种完整的嵌入式系统,集成了所有必要的组件。

https://blog.csdn.net/github_35631540/article/details/139122039

  • ESP8266
    • 应用场景:主要用于 WiFi 联网项目,如智能家居设备、IoT 传感器和无线控制。
    • 优势:低成本、内置 Wi-Fi 功能、低功耗模式,易于接入互联网。
    • 代表产品:NodeMCU 开发板、ESP-01模块。
  • 51单片机
    • 应用场景:广泛应用于教育和基础电子学习、简单的控制系统如家电控制、工业仪器等。
    • 优势:成本极低、指令简单、资源占用小,适合初学者和低成本项目。
    • 代表产品:Intel 的 MCS-51 系列。
  • ESP32
    • 应用场景:IoT设备,智能家居,低功耗传感器网络,音频应用等。
    • 优势:比 ESP8266 更强大的 CPU,支持蓝牙和 Wi-Fi,更多的 I/O 端口,更佳的安全性能。
    • 代表产品:ESP32 开发板。
  • Arduino
    • 应用场景:广泛用于教育、原型开发、艺术作品、简单的机器人。
    • 优势:易于学习的编程环境,丰富的社区和库支持,适合快速原型开发。
    • 代表产品:Arduino Uno, Arduino Mega。
  • STM32系列
    • 应用场景:汽车应用、工业控制、医疗设备、高性能嵌入式应用。
    • 优势:基于 ARM Cortex-M 核心,性能强大,低功耗,丰富的外设,支持多种开发环境。
    • 代表产品:STM32F103 系列、STM32F4 系列。
  • Raspberry Pi
    • 应用场景:作为学习计算机编程的工具、家庭媒体中心、高级DIY项目如自制服务器或游戏机。
    • 优势:具备完整的计算机功能,支持多种操作系统,拥有丰富的I/O接口和社区支持。
    • 代表产品:Raspberry Pi 4 Model B。

[嵌入式系统-72]:ARM芯片选型基础
https://blog.csdn.net/HiWangWenBing/article/details/138421375

  • 经典 ARM 处理器 ARMx
    • ARM7 系列:这是 ARM 处理器家族中较早的一代产品,采用 32 位 RISC 架构。
      • 广泛应用于嵌入式系统、移动设备等领域。
    • ARM9系列处理器是在ARM7基础上发展而来的,性能有明显提升。
      • 无线设备、仪器仪表、安全系统、机顶盒、高端打印机、数字照相机
    • ARM11 系列处理器是 ARM9 的升级
  • 嵌入式 Cortex-Mx系列:微控制器
    • 低成本、低功耗、高性能
    • 物联网(IoT)、工业自动化、智能家居和汽车电子等
    • 智能灯光控制、智能门锁、智能家电等设备中,实现远程控制和自动化管理。
  • 嵌入式 Cortex-R 系列:实时处理器
    • 实时处理器,专为需要高可靠性、高可用性、容错功能、可维护性和实时响应的嵌入式系统而设计。
    • 广泛应用于车载控制系统中,如发动机控制、车身控制、底盘控制等。在工业控制领域。
  • 高性能应用 Corex-A 系列:应用处理器
    • 高性能应用处理器,专为需要强大计算能力和高性能指令集的应用而设计
    • 广泛应用于智能手机、平板电脑、笔记本电脑等移动设备以及网络设备、存储设备等领域。

《龙之家族》血龙狂舞战争,黑党与绿党各有哪些势力?
https://zhuanlan.zhihu.com/p/569141727

ck 中按字符串列平均分成 10份

select count(*) from tbl
where CRC32(name)>= 0*((pow(2, 32) - 1) / 10)
and  CRC32(name) < 1*((pow(2, 32) - 1) / 10);
┌──count()─┐
│ 65588724 │ -- 65.59 million
└──────────┘
select count(*) from tbl
where CRC32(name)>= 1*((pow(2, 32) - 1) / 10)
and  CRC32(name) < 2*((pow(2, 32) - 1) / 10);
┌──count()─┐
│ 65424285 │ -- 65.42 million
└──────────┘

函数平移和伸缩变换的知识汇总
https://mp.weixin.qq.com/s?__biz=MzU0Mjg4ODc2OQ==&mid=2247488669&idx=1&sn=d7eafbfe91f41ed555e81e92ed9643d8

LLM101n: Let’s build a Storyteller
https://github.com/karpathy/LLM101n

thought through though

【tcp】关于tcp状态的Recv-Q 和 Send-Q
https://www.jianshu.com/p/4676ea4d03e1

TCP 半连接队列和全连接队列满了会发生什么?又该如何应对?
https://www.cnblogs.com/xiaolincoding/p/12995358.html

几种防御 SYN 攻击的方法:

  • 增大半连接队列;
    • 增大 tcp_max_syn_backlog 和 somaxconn
    • 增大 backlog
  • 开启 tcp_syncookies 功能
  • 减少 SYN+ACK 重传次数

开启 syncookies 功能就可以在不使用 SYN 半连接队列的情况下成功建立连接,在前面我们源码分析也可以看到这点,当开启了 syncookies 功能就不会丢弃连接。

syncookies 是这么做的:服务器根据当前状态计算出一个值,放在己方发出的 SYN+ACK 报文中发出,当客户端返回 ACK 报文时,取出该值验证,如果合法,就认为连接建立成功

https://www.languagereactor.com/ 这个学英语插件不错,可以每一句反复听,会自动断句。

所谓「不可能三角」,是指一款No Code工具无法同时兼顾「灵活」、「易用」与「效率」。

比如,如果工具:

支持各种场景(灵活),同时能显著提高网页产出效率,那他的配置一定很复杂(需要应对各种场景,不易用)
支持各种场景(灵活),同时很好用,那他的开发效率就不会高(无法无脑生成页面,需要修改产物代码)
配置简单(易用),同时开发效率高,那他的应用场景就窄(不灵活)
framer选择了第三条道路,即 牺牲灵活性,保持易用与效率。

具体来说,framer的应用场景局限在生成落地页、产品介绍页、官网这样的静态页。
https://framer.com/

C++11新特性
https://blog.csdn.net/qq_56044032/article/details/125230984

perl 菜鸟教程
https://www.runoob.com/perl/perl-tutorial.html
Perl 基本语法
https://www.cnblogs.com/cosiray/archive/2012/03/18/2404371.html
Modern Perl, 4e
http://modernperlbooks.com/books/modern_perl_2016/index.html

Google on Monday said the search company is reversing its plan to phase out the use of third-party cookies in its Chrome browser in favor of a new strategy that will allow people to “make an informed choice that applies across their web browsing.”

https://en.wikipedia.org/wiki/Denavit–Hartenberg_parameters

坐标系与矩阵(5): Denavit-Hartenberg算法
https://cloud.tencent.com/developer/article/1849681

在动力学中,比如人的胳膊就有好几个关节,且不同的关节有不同的旋转轴,如果是路飞的话,关节之间的长度还是不固定的。这里,每一个关节都存在一个自身坐标系,其中旋转可以是绕三个轴,平移则是沿着三个轴,每个坐标系存在6个自由度。问题就有点复杂了,每个人对每个关节可能会定义不同的坐标系方向,这会直接决定求解该问题的难度。DH算法则提供了一个一般性理论,且每一个关节只需要4个自由度。

https://cloud.tencent.com/developer/article/1969850
栅格化的对象是网格,网格表面可以通过三角形无限细分,而三角形是最简单的平面。接下来就是栅格化核心内容:如何绘制一个三角形。

栅格化的流水线主要有两个阶段:顶点(vertex)和片元(fragment),前者将三维空间下三角形的每一个点投射到二维平面上,后者则将投影后的三角形填充颜色,最终完成一个三角形的渲染。当多个三角形存在遮盖问题时,则通过深度检测(Z-buffer机制)来判断几何对象间的远近。

Whitted-Style Ray Tracing算法(1979)采用射线模拟相机到光源间的光路传输,并考虑了射线和光源之间的遮盖,射线和物体间的反射,以及和半透明物体间的折射等光学现象。该算法模拟了光线传播中的基本物理规律,比如Fresnel, Beer law,折射率以及传输过程中的衰减等,非常健壮的实现了阴影、折射、反射效果。

通过栅格化和光线追踪的发展来看,人们对真实感的定义随着时间而变化,最初希望有基本的阴影、折射、反射效果,随着技术和硬件能力的提升,人们的标准也不断的提高,正应了那句歌词,得不到的永远在骚动。这也反映了Moore‘s Law和Blinn’s Law之间的相互制约:当计算能力不断提升时,人们也会提高渲染真实感的标准,从而保证渲染时间不变。

在概念上,无论栅格化还是光线追踪,真实感的标准主有三点:照片级别(photo realistic)和物理正确(physically based rendering)以及性能(high performance),只是两者给出了不同的优先级。光线追踪优先前两点,往往需要极大的计算量,因此在离线渲染领域成为主角。而Rasterization技术主要应用于实时渲染领域,为了性能而有条件地牺牲前两点。

https://github.com/rqlite/rqlite

rqlite is a relational database which combines SQLite’s simplicity with the power of a robust, fault-tolerant, distributed system.

You can use rqlite to store your important data reliably, ensuring it’s always available. If you’re interested in understanding how distributed systems actually work, it’s a good example to study. A lot of thought has gone into its design, separating storage, consensus, and API clearly.

The fastest, most reliable, Redis-based distributed queue for Node.
Carefully written for rock solid stability and atomicity.
https://github.com/taskforcesh/bullmq

du -sh 排除挂载点,清理 /tmp

# 创建目录排除文件,排除掉非系统盘挂载点,NFS 挂载点 和 /proc
mount |awk '$1~/^\/dev/&&$3!="/" || $5~/nfs/ {print $3}' >> ~/.du_exclude
echo /proc >> ~/.du_exclude

# 查看文件大小分布
ncdu -X ~/.du_exclude /
du -sh -X ~/.du_exclude /*

# 清理 10 天未改动的临时文件
find /tmp -ctime +10 | xargs rm -rf