吹尽狂沙始到金
沉舟侧畔千帆过,病树前头万木春。 ——《酬乐天扬州初逢席上见赠》
如果说起最能体现刘禹锡的“诗豪”的诗句,我大概不会选最具代表性的“我言秋日胜春朝”,而是会选这一句。正如白居易所言“亦知合被才名折,二十三年折太多”,“二十三年”,一个从今天看来并没有多大的数字,背后的辛酸又有谁能知?而“怀旧空吟闻笛赋,到乡翻似烂柯人”颇有“笑问客从何处来”之感。整首诗沉郁,却不失豪放。正如这句诗,尽管似乎并不是想要表达“杀不死我的将使我更强大”的所谓的“乐观”,而是揭示了新旧事物更迭的自然规律,但是毫无疑问能从中感受到欣欣向荣的景象。所谓的“乐观”、“豪放”,并不应该是一天到晚叫嚣着“我不在乎”、“随他们去吧”,而是常常能于别人触景感伤处寻到乐趣,如从寂寥的秋天中看到鹤的排云直上,从沉舟侧畔看到千帆竞发,因此从这个角度上来说,刘禹锡比李白、苏轼更能称为“诗豪”
玄都观里桃千树,尽是刘郎去后栽。 ——《元和十年自郎州召至京师戏赠》
种桃道士归何处,前度刘郎今又来。 ——《再游玄都观》
我觉得这也是尽显刘禹锡豪情的地方,故地重游,加之因诗获罪,或了别人,或吃一堑长一智缄口不言,或感慨一句今昔对比, ...
UNIX 网络编程
基于 UNIX Network Programming, Volume 1: The Sockets Networking API, Third Edition 编写
套接字介绍
IPv4 套接字地址结构:
struct in_addr { in_addr_t s_addr; /* 32-bit IPv4 地址 */}struct sockaddr_in { uint8_t sin_len; /* 结构的长度 */ sa_family_t sin_family; /* 都是 AF_INET */ in_port_t sin_port; /* 16 bit TCP 或 UDP 端口号 */ struct in_addr sin_addr; /* 32 bit IPv4 地址,网络字节顺序 */ char sin_zero[8]; /* 未使用,全是 0 */}
一般只需要设置中间三个成员即可
有更广泛的 socket 地址结构:
struct sockaddr { uint8_t sa_len; ...
Test
Benchmark
JMH
jmh(Java Microbenchmark Harness) 是 Java 微基准测试框架,可以用于比较 Java 程序的性能好坏
万物皆可 hello world:
package org.openjdk.jmh.samples;import org.openjdk.jmh.annotations.Benchmark;import org.openjdk.jmh.runner.Runner;import org.openjdk.jmh.runner.RunnerException;import org.openjdk.jmh.runner.options.Options;import org.openjdk.jmh.runner.options.OptionsBuilder;public class JMHSample_01_HelloWorld { @Benchmark public void wellHelloThere() { } public static void ...
C++ Concurrency In Action
基于 C++ Concurrency In Action Second Edition 编写
C++ 并发世界
并发 concurrency 是指两件或更多分开的活动在同时发生
单核 CPU 通过 context switch 来形成多个任务在同时执行的假象
多核 CPU 原理也类似
并发的方法:
多进程
多线程
并发和并行 parallelism 概念类似,但是
并行通常更考虑效率
并发则关心关注点分离
故使用并发的情况:
关注点分离
任务和数据的并行
C++ 中原来没有关于并发的标准,和 C 语言一样使用操作系统提供的 API。从 C++11 开始,封装了较一般的 thread 等
从并发版的 hello world 开始:
#include <iostream>#include <thread>void hello() { std::cout << "Hello, World" << std::endl;}int main() { std::thread t( ...
Butterfly 博客魔改
音乐
这里直接采用 html 的格式
<div class="aplayer" data-id="760533" data-server="netease" data-type="song"></div>
效果:
参数解释:
选项
description
data-id
song id / playlist id / album id / search keyword
data-server
音乐平台:netease、tencent、kugou、xiami、baidu
data-type
song、playlist、album、search、artist
关闭 asset_inject:
_config.ymlaplayer: meting: true asset_inject: false
开启主题的 aplayerInject:
_config.butterfly.yml# Inject the css and script (aplayer/m ...
Hexo 和 Butterfly 搭建博客
Hexo 是基于 Nodejs 开发的博客框架,简单,扩展性强。尽管性能不是很强,但对于轻量使用博客来说已经足够了
第一个 Hexo 博客
安装 Hexo:npm install -g hexo-cli
初始化项目名:hexo init 项目名
生成的项目结构如下:
文件夹名
说明
node_modules
依赖包
scaffolds
生成文章的模板
source
用来存放你的文章
themes
主题
.npmignore
发布时忽略的文件
_config.landscape.yml
主题的配置文件
_config.yml
博客的配置文件
package.json
项目名称、描述、版本、运行和开发等信息
启动项目:hexo s
在 http://localhost:4000/ 中可以看到页面
这里使用 GitHub Pages 部署博客,按照说明新建用户仓库
安装 hexo-deployer-git:npm install hexo-deployer-git
修改文件:
_config.yml# Deployment## Docs: ht ...
UML
基于 UML Distilled Third Edition: A Brief Guide to the Standard Object Modeling Language 编写
在线画图网站:draw.io
简介
统一建模语言 Unified Modeling Language(UML) 是图像标记家族,通常用于面向对象编程中
标准由 OMG 制定
UML 通常有三种用法:
草稿——最常用
蓝图
编程语言
两个时间阶段:
前向工程:在写代码之前画图
逆向工程:从现有的代码中构造 UML 图以帮助理解代码
也正因为前两种用法更常见,故应该力求简洁,抓住要点,就像设计模式一样,通过公认的规范让人能够快速抓住要点。所以在使用的过程中要尽量避免那些微妙的歧义之处
类图
类图是最常见的图之一
属性 properties 代表类的结构化特征,有两种标记方式:
Attribute:直接写在类的框图中
通常语法如下:可见性 名字: 类型 乘数 = 默认值 {属性字符串}
例如:- title: String [1] = "Untitled" ...
WSL2
邪教——适用于 Linux 的 Windows 子系统(WSL2)
尽管 WSL2 中的 Linux 内核是不完整的,但几乎已经足够使用了。而且其无论是启动速度还是易用性方面都比虚拟机好得多,而且 IP 地址相同
参考文档:适用于 Linux 的 Windows 子系统文档 | Microsoft Learn
安装
wsl --install
查看可用非发行版:wsl --list --online
列出已安装的版本:wsl --list --verbose
安装指定 Linux 发行版:wsl --install -d <distribution name>
运行指定 Linux 发行版:wsl --distribution <Distribution Name>
设置默认 Linux 发行版:wsl --set-default <Distribution Name>
关闭:wsl --shutdown
设置开发环境
换源:使用中科大源
这里使用的是最新的 Ubuntu 24.04,使用其提供的命令:
sudo sed -i 's@//. ...
故乡
友谊
他站住了,脸上现出欢喜和凄凉的神情; 动着嘴唇,却没有作声。他的态度终于恭敬起来了,分明的叫道:
“老爷! ……”
我似乎打了一个寒噤;我就知道,我们之间已经隔了一层可悲的厚障壁了。我也说不出话。
只能说把鲁迅的文章放到中学课本中实在是太超前了,以至于在我第一次看到这篇文章时,只记得了文末的那段名句,还有已经被玩坏的“闰土刺猹”的梗,居然没有被这一段文字给深深地震撼到。“一层可悲的厚障壁”居然还是一道思考题,当年回答的时候绞尽脑汁把一些语文阅读理解的套路的词语往里面套,现在那堵墙似乎就堵在我面前一样,深深的无力感就那样横在面前,无需多言。
友谊怎么写最刀?不是互相背叛,不是迫于无奈走向了对立面,而是一下子从理想跌落到现实产生的落差。
张华考上了北京大学;李萍进了中等技术学校;我在百货公司当售货员:我们都有光明的前途。
曾记得当我第一次拿到一本新华字典的时候,我爱不释手,尤其喜欢看最后的那部分,朝代的更替还是我在那里学到的呢。这一句话我似乎有点印象,是用来演示某个标点符号用法的例句,当时我并没有在意。现在看来,确实是充满了讽刺意味。不知道是否有一段时期这三者能平起平坐,甚至 ...
Effective Modern C++
基于 Effective C++: 42 Specific Ways to Improve Your Use of C++11 and C++14 编写
推断类型
理解模板类型推断
在模板类型推导中,引用参数被视为非引用
对通用引用 && 参数,左值参数特别对待
在按值传递参数时,const 和 volatile 参数被视为非 const 和非 volatile
在模板类型推导中,数组或函数名参数退化为指针,除非被用于初始化引用
理解 auto 类型推断
auto 通常和模板类型推断一样,但是 auto 类型推断将大括号初始化 {} 视为 std::initializer_list,模板类型推断不这样
函数返回值中的 auto 或 lambda 参数是函数模板推断,不是 auto 类型推断
理解 decltype
decltype 在没有任何修改的情况下,几乎总是生成变量或表达式的正确类型
对于不同于名字的类型为 T 的左值表达式,decltype 总是返回 T&
decltype(auto) 类似于 auto,从初始化推断类型,但是使用了 ...
设计模式
基于 Design Patterns: Elements of Reusable Object-Oriented Software 编写
介绍
设计模式有四大必备元素:
模式名
问题:何时应用此模式
解决方案:应用于不同情况下的模板
后果:应用该模式的结果与取舍
多种设计模式可以组合使用,事实上也经常组合使用
设计模式解决问题的方法:
找到合适的对象
确定对象的粒度
具体说明对象接口
具体说明对象实现
类与接口继承
给接口编程,而不是向实现
为了让复用机制生效
继承与组合——倾向于组合
指派
继承与参数化类型
运行时和编译时结构
aggregation:一个对象拥有另一个对象,即两者有相同的生命周期
acquaintance:一个对象仅仅知道另一个对象
为改变而设计:
通过
应用程序:
工具集
框架
创建模式
抽象工厂 Abstract Factory
目的:在具体说明具体类的情况下创建相关的对象家族
应用
一个应该被配置为多种产品家族之一的系统
一个家族的相关产品被一起使用
提供一类库的产品
结构
参与者
抽象工厂 - 具体工厂
抽象产品 - 具体产品 ...
植物大战僵尸
逆天评论
150 可以买双子向日葵,而火树只要175,我的意思是,虽然可以玩姐妹花,但我宁愿多花点钱也要玩个烧的
只要在寒冰射手前面放两根火炬树桩,就会变成火焰豌豆。我的意思是不管外表多高冷,两根就受不了
一般的植物都可以放在南瓜里保护起来,但是玉米加农炮不行,所以只要够大就可以不带
大喷菇升级成春哥以后能喷三路,我的意思是有钱哪个位置都能玩
虽然开局50阳光可以下向日葵,但是我选择25阳光的阳光菇等他长大,花一半的钱从小玩到大
大嘴花一口就能把僵尸吃掉,而豌豆射手却需要很久才能杀掉僵尸,我的意思是,口一下就能解决的事没必要那么麻烦
蘑菇在白天不能发挥作用,但是使用咖啡豆就可以,我的意思是实在不行下点药也能玩
南瓜罩可以保护大部分植物的安全,但毁灭蘑菇依然会炸出一个坑。我是说足够大足够强,套了也没用。
冰西瓜投手很贵,但是伤害高又很冷,我的意思是,只要你有钱,再高冷的都能拿下
在你犯错时为你兜底,在你成功时给你奖励。——小推车
仙人掌要125阳光,只能发出一排尖刺,而猫尾草225阳光却可以全图追踪. 我的意思是:多给一点,她会更灵活
我的意思是,前后夹击不如朝一个方向用力耕 ...