Skip to content

Instantly share code, notes, and snippets.

View jiacai2050's full-sized avatar
:shipit:

Jiacai Liu jiacai2050

:shipit:
View GitHub Profile
@jiacai2050
jiacai2050 / libpq-demo.cc
Created December 28, 2023 14:35 — forked from ictlyh/libpq-demo.cc
libpq examples.
/*
* Demo of libpq.
* Build: g++ libpq-demo.cc -o libpq-demo -lpq
* Run: ./libpq-demo
*/
#include <arpa/inet.h>
#include <iostream>
#include <libpq-fe.h>
#include <sstream>
@jiacai2050
jiacai2050 / gist:4130861eba1c4b13505259d28d158091
Created December 18, 2023 07:22 — forked from payam-int/gist:edf977c6af603fee0ce1b05da7792fe7
Prometheus Node Exporter - CPU and Memory Usage

CPU Usage :

(1 - avg(irate(node_cpu_seconds_total{mode="idle"}[10m])) by (instance)) * 100

Memory Usage :

100 * (1 - ((avg_over_time(node_memory_MemFree_bytes[10m]) + avg_over_time(node_memory_Cached_bytes[10m]) + avg_over_time(node_memory_Buffers_bytes[10m])) / avg_over_time(node_memory_MemTotal_bytes[10m])))
@jiacai2050
jiacai2050 / podcast-fetcher.go
Created November 27, 2023 13:55
Download podcasts
package main
import (
"encoding/xml"
"flag"
"fmt"
"go-apps/pkg/flagx"
"go-apps/pkg/util"
"io"
"log"
1
00:00:00,000 --> 00:00:06,800
大家好,今天是2021年6月27号,是InMessTalk的第一期。
2
00:00:06,800 --> 00:00:11,700
这一期主要由我来讲一下这个节目的背景。
3
00:00:11,700 --> 00:00:17,200
@jiacai2050
jiacai2050 / find-tcp-last-communiate-time.md
Created June 11, 2023 12:05
如何找出 TCP 连接建立时间与最后一次通讯时间

这个问题是在《形单影只的 Socket》最后留的问题,这里给出一个思路供大家参考,看下那篇文章再来看这个效果可能会更好。

传送门: 测试环境:Ubuntu 14.04 好了,进入正题。首先构造一个 TCP 连接,这里使用形单影只的 socket 来启动一个 echo server

$ nc -vp 11111 localhost 11111
Connection to localhost 11111 port [tcp/*] succeeded!

$ ss -ap | grep 11111
[dependencies]
rand = "0.8.5"
xorfilter-rs = { git = "https://github.com/datafuse-extras/xorfilter", features = [
"cbordata",
], tag = "databend-alpha.4" }
@jiacai2050
jiacai2050 / tree.zig
Last active April 24, 2023 15:10
Tree(1) in Zig
//! Tree(1) in Zig
//! https://linux.die.net/man/1/tree
const std = @import("std");
const process = std.process;
const fs = std.fs;
const mem = std.mem;
const testing = std.testing;
const VisitedEntry = struct {
@jiacai2050
jiacai2050 / async_await_cancellation.md
Created January 13, 2023 12:22 — forked from Matthias247/async_await_cancellation.md
Async/Await - The challenges besides syntax - Cancellation

Async/Await - The challenges besides syntax - Cancellation

This is the second article in a series of articles around Rusts new async/await feature. The first article about interfaces can be found here.

In this part of the series we want to a look at a mechanism which behaves very different in Rust than in all other languages which feature async/await support. This mechanism is Cancellation.

@jiacai2050
jiacai2050 / mu4e-config.el
Created August 29, 2022 13:13
Emacs mu4e config
;; Mail start
(use-package mu4e
:ensure nil
:if (executable-find "mu")
:commands (mu4e)
:bind (:map mu4e-view-mode-map
("f" . mu4e~headers-jump-to-maildir)
("9" . scroll-down-command)
("0" . scroll-up-command)
("&" . my/open-url-in-external)
//! `yes` unix command in Zig, optimized for speed
//! Reference to: https://github.com/cgati/yes
const std = @import("std");
const BUFFER_CAP = 64 * 1024;
fn fill_up_buffer(buf: *[BUFFER_CAP]u8, word: []const u8) []const u8 {
if (word.len > buf.len / 2) {
return word;