Posts
All the articles I've posted.
jemalloc C++实践
Published: at 10:13 AMjemalloc是一种通用的malloc(3)实现,优点是避免内存碎片和可伸缩并发支持。 下载源码 wget https//github.com/jemalloc/jemalloc/releases/download/5.2.1/jemalloc-5.2.1.tar.bz2 解压 tar -jxvf jemalloc-5.2.1 编译安装 cd jemalloc-5.2.1 ...
C++11 实现defer
Published: at 01:56 AMdefer函数功能还是蛮常用的,它是在出当前作用域的时候执行,用来回收资源非常合适,可惜C++里面没有,以前实现起来都比较别扭现在用C++11实现后看起来简单多了。 此defer内部lambda表达式捕获的是引用; 同一个作用域内先定义的defer后执行; 使用define以及xy连...
微信本地图片格式转化
Published: at 02:52 PMPC端微信收到的图片存储在本地,我们可以打开微信的设置->通用设置->文件管理->打开文件夹,在FileStorage/Image日期目录下找到图片文件,但是它经过了简单的加密并且后缀为.dat。 通过下面这个算法可以将dat文件还原成原始图片,目前支持jpg,gif,png三种格式,其他格式应该...
golang vscode launch.json配置
Published: at 01:07 PM每次调试运行都要先打开main.go然后在菜单里点击Run->Start Debugging或者F5比较麻烦,主要是每次都要定位了main.go文件,这样当我编辑完其他文件后,都要切换一下才能运行。 下面增加一下Launch.json配置就可以直接点击左侧的debug按钮运行了,在Launch菜单下的Add Con...
gin多模板、模板嵌套使用方法
Published: at 11:36 AM在做一个web应用的时候,通常多个页面会共用同一个模板,只是每个页面的内容不同。如网页的导航栏、菜单栏、footer是共用的。我们写代码的时候也只需要写一个主模板页面frame.html,内容空出来给具体的页面来实现,如:主页index.html,文章页面post.html,错误页面error.html等等,...
Qt 正确的显示窗口
Published: at 06:47 AM显示窗口看起来很简单,但是有一些细节要注意的。通常有下面几种情况需要展示一个窗口: 1. 第一次创建后展示 2. 窗口最小化 3. 窗口不在最前面 4. 窗口销毁后再次创建(同第1种) 注意: 这里说的不是通过任务栏来激活窗口,而是通过用户设计的按钮或者菜单来打...
golang接口型函数作用
Published: at 03:46 AM在我们使用golang写http服务的时候通常会使用http.Handle来注册pattern对应的Handler,其实这里就使用到了接口型函数,源码定义如下: type Handler interface { ServeHTTP(ResponseWriter, Request) } type HandlerFunc func(ResponseWriter, Request) func (...
QTableWidget整行高亮去虚线,样式定制
Published: at 02:56 AM很常见的一种需求,但是很可惜Qt没有一种比较简单的实现方式。在网上找了很多资料也没有找到,实现方法比较复杂,但是经过 我的实验,下面这种方法是可行的,而且有很多意想不到的好处。 定义接口类 存储当前hovered行,split行是实现其他需求的可以不考虑 class IVie...
Qt json文件读写
Published: at 02:48 AMQt提供了处理JSON数据的支持。JSON是一种数据编码格式派生自Javascript,现在在internet上广泛用作数据交换格式。 Qt中的JSON支持提供了一个易于使用的C++ API来解析、修改和保存JSON数据。 它还支持以二进制格式保存数据,这种格式可以直接“mmap”,而且访问速度非常快。 简...
字符编码的故事
Published: at 01:40 PM很早之前看过的文章,转载过来记录下。 字符编解码的故事(ASCII,ANSI,Unicode,Utf-8) 很久很久以前,有一群人,他们决定用8个可以开合的晶体管来组合成不同的状态,以表示世界上的万物。他们认为8个开关状态作为原子单位很好,于是他们把这称为"字节"。 再后来,他们...