🚙

💨 💨 💨

×

  • Categories

  • Archives

  • Tags

  • About

A optimized Hexo & Next.

Posted on 01-18-2013 | In Misc

This blog is powered by my open-source project, made by me in 2013, hexo-theme-neo

I’ve optimized the original NexT theme and many hexo plugins through numerous code modifications, including:

  • Implemented headroom.js for auto-hiding header: hides on downward scroll, reappears on upward scroll
  • The optimization of the animation. Now, even an extremely long blog article with tens of thousands of words won’t freeze.
  • Buttons that allow the sidebar to be fully expanded and the logic for double - clicking to expand it individually have been added, along with different markings for different levels of headings, making it clearer.
  • Mobile-first improvements:
    • Restructured header layout
    • Unified sidebar behavior between mobile/desktop
    • Scrollable table of contents on mobile
  • Added article encryption support
  • Replaced Fancybox with mediumzoom for superior image zoom experience
  • Redesigned local search engine:
    • Fixed keyboard pop-up issues on mobile
    • Excludes encrypted articles from search results
    • Added elegant transition animations

Usage

  1. Download Node.js version 10.13.0 here and verify with node -v. Using this specific version is crucial—do not modify it.
  2. Delete the source folder in this project.
  3. Create a new source folder.
  4. Run npm install -g hexo-cli, then npm install --force.
  5. Extract my_node_modules.tar.gz into the current directory tar -zxvf my_node_modules.tar.gz(Ensure Hexo is installed before running this step)
  6. Learn Hexo’s base usage for Writing/Generating/Deployment .
  7. Learn NexT. Explore NexT’s documentation for theme-specific configurations.
  8. Modify the configuration files: /_config.yml and /themes/next/_config.yml
  9. Run hexo clean to remove cached files.
  10. Run hexo generate to generate static files.
  11. Run hexo server to start a local Hexo server.

. . .

A userscript that adds a table of contents to any website

Posted on 08-25-2022 | In GitHub

auto-toc

auto-toc

Displays a table of contents for any website, making it easier to read and navigate long articles, documentations, and online books.

Generate TOC(table of contents) for any website.

Switch black/white themes automatically according to your compupter’s light/dark mode.

Features

  • Work properly on any website that conforms to the HTML standard and uses HTML heading tags properly (e.g. Wikipedia.com).
  • Accurate article and heading detection
  • A clean user interface
  • Highlight current heading
  • Click to jump to headings
  • Drag the panel to your preferred position
  • Only runs when you actually use it
  • Dark mode, automatically
  • 6 heading levels
  • Expand all headings to a specific level
  • Support HTML label:
    • H1, H2, H3, H4, H5, H6
    • <strong>
    • <b>

. . .

A shell plugin that provides interactive Tab search & completion for any path

Posted on 08-22-2022 | In GitHub

tab-to-find

tab-to-find

One tab enables interactive and dynamic search for everything!!

It also supports tab dynamic completion of commands for the paths of any directories and files.

It is extremely useful for people who often need to find files and are troubled by entering very long paths. There is no need to type the paths one by one slowly. You can search and reach the target in one step. Even if there are millions of files, it is still very smooth and not laggy at all.

Abbreviation: TTF

Demo

tab-to-find-demo.gif

features

  • Just press tab as usual.
    • Without entering anything, tab can directly and dynamically search for all directories and files in the current directory and its subdirectories. It’s also very useful just as a search tool.
    • Use tab to autocomplete.
      • It doesn’t necessarily have to be an exact match at the beginning. For example, if you enter doc and then press tab, it can match test_doc, doc_test, and test_doc_test.
      • It can recursively match all files/directories with doc in the subdirectories of the current directory. That means you can enter cd doc in the home directory and directly cd from the home directory to ~/github/test - proj/documents in one step!
        • If there is only one match, it will be automatically completed.
          • For example, if it matches Documents/, but if that’s not what you want and you want ~/github/test - proj/documents, you can press tab again.
        • If there is more than one match, it will recursively search all folders containing doc in the subdirectories.
      • If what follows cd is not a directory, it will automatically enter the directory where that file is located. For example, if you enter cd ~/github/test.txt, it can directly enter the ~/github folder.
      • If the input ends with //, it can search only for folders in one level of the directory, instead of recursively searching all subdirectories.
      • If the input ends with .., it can search only for files in one level of the directory, instead of recursively searching all subdirectories.
      • The same applies to other commands such as vi, ln, mv, cp, etc.

Usage

  • Press tab to search everything
  • Press tab for completion as usual

. . .

An alternative to Alfred+Wox+Listary+OneQuick+CapslockPlus

Posted on 01-09-2020 | In GitHub

sux

  • Zhihu link
  • Download link

sux is a powerful productivity tool with a size of only 2M+. It also has the following features:

  • Translation
  • History Clipboard
  • Everything Search Toolbar
  • Screenshot & Pinning
  • Quick Search Similar to listary/alfred/wox
  • Hot Corners Similar to macOS
  • Hot Edge Triggers
  • Fully Customizable Global Shortcuts for Various Operations
  • Text Replacer
  • Text Transformer
  • Tray Menu
  • CMD Commands
  • Customizable JSON Configuration
  • Custom Themes
  • etc …

An alternative to Alfred/Wox/Listary/Capslock+/OneQuick .

Inspired by Alfred/Wox/Listary/Capslock+/utools/OneQuick, thank u.

. . .

A lightweight KCP session implementation

Posted on 08-09-2018 | In NP

kcpp

Lightweight KCP Session Implementation - kcpp

kcpp truly enables you to use KCP just by including a single header file and writing a few lines of code, without having to worry about how to organize the code to adapt to KCP.

  • You only need to include the single header file kcpp.h.
  • You only need to call KcpSession::Send, KcpSession::Recv, and KcpSession::Update to complete UDP connection state management, session control, and RUDP protocol scheduling.

What is KCP?

KCP is a high-performance, reliable, and lightweight transport layer protocol designed to accelerate UDP-based data transmission. It provides an efficient alternative to TCP while maintaining UDP’s low-latency benefits. Originally developed by skywind3000, KCP is widely used in real-time applications such as gaming, live streaming, VPNs, and P2P networking.

Features

  • Single-header-only
  • Session implementation
  • Dynamic redundancy
  • Two-channel
    • Reliable
    • Unreliable

kcpp Examples

  • realtime-server: A real-time dedicated game server (FPS / MOBA).
  • realtime-server-ue4-demo: A UE4 state synchronization demo for the real-time server. Video Preview

kcpp Usage

The main loop is supposed to be as follows:

Game.Init();

// kcpp initialization
kcpp::KcpSession myKcpSess(
KcpSession::RoleTypeE,
std::bind(udp_output, _1, _2),
std::bind(udp_input),
std::bind(timer)
);

while (!isGameOver) {
myKcpSess.Update();

while (myKcpSess.Recv(data, len)) {
if (len > 0) {
Game.HandleRecvData(data, len);
} else if (len < 0) {
Game.HandleRecvError(len);
}
}

if (myKcpSess.CheckCanSend()) {
myKcpSess.Send(data, len);
} else {
Game.HandleCanNotSendForNow();
}

Game.Logic();
Game.Render();
}

The Recv, Send, and Update functions of kcpp are guaranteed to be non-blocking.
Please read TestKcppClient.cpp and TestKcppServer.cpp for some basic usage examples.

KCP Source Code Annotations

This project also comes with an annotated version of the KCP source code, ikcp.h and ikcp.c. It can be regarded as another detailed explanation of KCP, which is convenient for self-study and helps others get started more quickly. The original code is from: https://github.com/skywind3000/kcp. Thanks to skywind3000 for bringing such a concise and excellent project.

Readers interested in open-source projects for real-time combat games like FPS / MOBA can also visit realtime-server. Welcome to communicate.

Note: Tabs are used for indentation in the project, and tab is set to 2 spaces.

Almost every paragraph has annotations, and key data structures are accompanied by diagrams. For example:

...
//
// The data packets sent by KCP have their own packet structure. The packet header is 24 bytes in total and contains some necessary information. The specific content and size are as follows:
//
// |<------------ 4 bytes ------------>|
// +--------+--------+--------+--------+
// | conv | conv: Conversation, the session serial number used to identify whether the sent and received data packets are consistent.
// +--------+--------+--------+--------+ cmd: Command, the instruction type, representing the type of this Segment.
// | cmd | frg | wnd | frg: Fragment, the segmentation serial number. The segments are numbered from large to small, and 0 indicates that the data packet has been received completely.
// +--------+--------+--------+--------+ wnd: Window, the window size.
// | ts | ts: Timestamp, the sending timestamp.
// +--------+--------+--------+--------+
// | sn | sn: Sequence Number, the Segment serial number.
// +--------+--------+--------+--------+
// | una | una: Unacknowledged, the current unacknowledged serial number,
// +--------+--------+--------+--------+ which means that all packets before this serial number have been received.
// | len | len: Length, the length of the subsequent data.
// +--------+--------+--------+--------+
//
...

//---------------------------------------------------------------------
// ...
// rcv_queue: The queue for receiving messages. The data in rcv_queue is continuous, while the data in rcv_buf may be intermittent.
// nrcv_que: The number of Segments in the receiving queue rcv_queue, which needs to be less than rcv_wnd.
// rcv_queue is shown in the following diagram:
// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
// ... | 2 | 3 | 4 | ...............................................
// +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
// ^ ^ ^
// | | |
// rcv_nxt rcv_nxt + nrcv_que rcv_nxt + rcv_wnd
//
// snd_buf: The buffer for sending messages.
// snd_buf is shown in the following diagram:
// +---+---+---+---+---+---+---+---+---+---+---+---+---+
// ... | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ...........
// +---+---+---+---+---+---+---+---+---+---+---+---+---+
// ^ ^ ^
// | | |
// snd_una snd_nxt snd_una + snd_wnd
//
//
// rcv_buf: The buffer for receiving messages.
// rcv_buf is shown in the following diagram. The data in rcv_queue is continuous, while the data in rcv_buf may be intermittent.
// +---+---+---+---+---+---+---+---+---+---+---+---+---+
// ... | 2 | 4 | 6 | 7 | 8 | 9 | ...........
// +---+---+---+---+---+---+---+---+---+---+---+---+---+
//
...

. . .

A lightweight game server engine

Posted on 05-02-2018 | In GitHub

Architecture Diagram

This architecture diagram is automatically generated by writing PlantUML.

Key Features

  • Business layer development based on ECS framework: You can inherit from the base entity class and base component class.
  • Integrated service mechanism based on etcd: It includes service registration, TTL, service discovery, load balancing, load reporting, and Watch mechanism.
  • RPC framework based on msgpack: It supports direct calling via IP address and direct calling of remote virtual entities/components in combination with ECS.
  • Coroutine business layer support based on asyncio asynchronous IO: You can achieve the effect of directly calling RPC and getting the return value like result = await rpc_call().
    • A coroutine pool is implemented and encapsulated into a concise decorator for easy calling in the business layer.
  • Support for TCP and RUDP
  • Asynchronous HTTP microservice framework based on Sanic: It is convenient for developing various public services.
    • An authentication module based on JWT.
    • A data persistence module based on Redis.
    • An ODM module based on Umongo.
  • Hot - update reload module:
    • Full - scale update: Stable.
    • Incremental update: Faster, convenient for daily development.
  • Asynchronous TimedRotating log module support:
    • Automatically rolls over log files according to date and time.
    • Supports callbacks of coroutine objects.
    • Changes colors according to log levels for easy querying.
    • Prints the stack and locals when reporting traces.
    • Provides file jump support in PyCharm for log levels above warning.
  • Timer module supporting 1:N model: It avoids the error - prone issue of overwriting the same key.
    • You can reuse a key without overwriting the previous timers associated with the key. However, when calling cancel_timer, all timers with the same key will be cancelled at once.
  • Enhanced JSON parser: It supports comments, automatic removal of commas, and variable macros.
  • Data persistence module based on MongoDB
  • Client - side simulation and automated testing support
  • Pre - gateway gate server for the lobby server: It is responsible for data compression/decompression, encryption/decryption, and authentication.

Python Version

Python 3.8.8

Q&A

Here are the answers to common questions. Please don’t spam the group with these questions:

  • Where can I find the old version?
    • Do you mean the CPP version in the following demo image? It’s in the master branch.
  • Why choose Python for the new version instead of C++? Or why not make C++ the bottom layer and Python the upper layer?
    • It’s possible to use C++ as the bottom layer and Python as the upper layer for calling. However, the current vision is to encourage more developers to contribute. The threshold of C++ is significantly higher than that of Python for other contributors.
    • If there are enough users in the future, we will consider making the bottom layer in C++ and packaging it into .pyd or .so for the upper layer to call.
    • For most games, the performance of Python is sufficient.
    • The vision of this server engine is to target mass developers for rapid development. Python has a wide audience and is easy to learn.
  • What’s the significance of lobby_gate? Why doesn’t the client connect directly to the lobby?
    • Generally, when latency is not a critical issue, the client accesses the lobby through the gate. The gate is responsible for proxying and forwarding network communication data between the client and the game. It also handles data encryption, decryption, compression, and decompression, reducing the performance pressure on the lobby.
    • The logic of message processing in the lobby can be simpler without dealing with I/O multiplexing, as all messages come from a single TCP connection (single gateway) or a fixed number of TCP connections (multiple gateways).
    • After the client starts, it connects to the gateway, which then connects to the scene server and forwards all message packets. When switching scenes, the connection between the client and the gateway remains intact. The gateway is responsible for connecting to the new scene. Since the gateway and the game server are usually in the same local area network, the problem of disconnection is greatly improved.
    • In a multi - process online game architecture, the game server not only processes client messages but also messages from other processes such as accounts and GM tools. For security reasons, it is necessary to isolate and restrict client messages.
    • Game servers often need to start new servers, merge servers, or migrate due to hardware failures. If the game server directly provides services to the client, the client usually needs to log out and log in again when the service changes. If a gateway is used, when the server address changes internally, only the gateway needs to be updated and reconnect, and the client may not even notice.
  • What is RUDP?
    • Its full name is reliable UDP.
    • Currently, this server engine is implemented in Python based on the standard KCP algorithm.
    • There are plans to improve KCP in the future, and the performance will be further enhanced. Stay tuned:
      • Add a dynamic redundant packet mechanism based on SRTT monitoring.
      • Simplify the packet header (for example, some fields in the packet header do not need 32 bits and can be changed to 16 bits).
      • Introduce the dupack mechanism, not just sending IKCP_CMD_ACK packets.
        • Make full use of the fields in the packet header. For example, when the number of ACKs to be sent in the ACK list array is less than or equal to 3, use the len, rdc_len, and sn in the packet header to represent the sequence numbers of the received packets.
        • Redundant ACK mechanism: When the number of ACKs to be sent in the ACK list array is greater than 3, the body will contain all the ACKs in the merged ACK list and the previously sent ACKs until the packet size reaches the MSS.
      • …
  • What about etcd?
    • It implements service registration, service discovery, load balancing, and load reporting through its TTL and Watch mechanisms.
    • It is convenient for implementing distributed locks.
    • The V2 version of the HTTP API is used for interacting with etcd. Since the interaction is not sensitive to latency, gRPC is not used to keep it simple.
    • Then why choose etcd instead of ZooKeeper?
      • The purposes of the two applications are different. The purpose of etcd is to be a highly available Key/Value storage system, mainly used for sharing configurations and service discovery; the purpose of ZooKeeper is to be a highly effective and reliable collaborative working system.
      • The interface call methods are different. etcd is based on an HTTP + JSON API, which can be easily used with just curl, making it convenient for each host in the cluster to access; ZooKeeper is based on TCP and requires a dedicated client.
      • The functions are quite similar. Both etcd and ZooKeeper provide key - value storage services, cluster queue synchronization services, and the ability to observe changes in the value of a key.
      • The deployment methods are also similar: They both use a cluster mode and can support thousands of nodes. etcd is written in Go and can be deployed by directly compiling the binary files; ZooKeeper is written in Java and depends on JDK, so JDK needs to be deployed first.
      • Implementation languages: Go has almost the same efficiency as C, especially since Go is a language designed for multi - threading and process communication, and it performs very well in small - scale clusters; Java requires more code to implement, and its performance is average in small - scale clusters. However, after optimizing multi - threading in large - scale scenarios, its performance is not much different from that of Go.

. . .

A powerful sux-like productivity tool on Mac

Posted on 03-14-2025 | In GitHub

sux-mac

A powerful sux-like productivity tool on Mac. 一个 Mac 端的类似 sux 的强大效率工具.

features

  • Clipboard history supports both text and images. You can select a single item for copying, and it also allows you to copy all the contents in the clipboard history at once.
    • alt text
  • Automatically switch input method:
    • Every time you switch software, it will automatically prompt the current input method status.
      • alt text
    • Remember the input method used by each software last time, and automatically switch the input method according to the software. For example, after you switch from Chinese to English input method in software A, then go to B to use Chinese input method. When you go to software A, it will automatically switch to English input method.
  • Automatically maximize the window. After setting the software list, it will automatically maximize the window when these software are opened.
  • Implement text input enhancement, you can use the Capslock key with the following auxiliary keys to achieve most of the text operation requirements, no longer need to switch back and forth between the mouse and keyboard, can be similar to vim, various cursor movements are very convenient
    • You can fully customize
    • default settings:
      • Capslock + J: down
      • Capslock + K: up
      • Capslock + H: left
      • Capslock + L: right
      • …
  • Detect corners and edges and use Hammerspoon to set custom actions, and dual monitors are also supported.
    • You can fully customize
    • default HotEdges settings:
      • Quickly touch the top left half edge of the screen twice to maximize the window
      • Quickly touch the top of the screen twice right half the edge, you can slide to the top of the window
      • Quickly touch the bottom of the screen twice right half the edge, you can slide to the bottom of the window
      • Quickly touch the left edge of the screen twice with the mouse, you can turn the window into half the size of the screen and paste it on the left edge of the screen
      • Quickly touch the right edge of the screen twice to turn the window into half the size of the screen and stick it to the right edge of the screen
      • When you have two monitors, right-click on the top left half edge of the screen to move the window to the left side of the monitor and maximize it
      • When you have two monitors, right-click on the top right half edge of the screen to move the window to the monitor on the right side and maximize it
      • …
    • default HotCorners settings:
      • Mouse touch upper left corner: previous page (such as the previous tab of the webpage, the previous tab of vscode)
      • Mouse the upper right corner: next page (e.g. the next tab of the web page, the next tab of vscode)
      • Mouse touch in the lower left corner: Switch to the previous software
      • Mouse the upper right corner: next page (e.g. the next tab of the web page, the next tab of vscode)
      • …

Usage

  1. Install the Hammerspoon software: https://www.hammerspoon.org
  2. Place the .hammerspoon folder in your user home directory.
  3. Launch Hammerspoon and reload the configuration:
    • alt text

. . .

1234567891011…36
Mike

Mike

🚙 🚗 💨 💨 If you want to create a blog like this, just follow my open-source project, "hexo-theme-neo", click the GitHub button below and check it out ^_^ . It is recommended to use Chrome, Safari, or Edge to read this blog since this blog was developed on Edge (Chromium kernel version) and tested on Safari.

11 categories
287 posts
110 tags
about
GitHub Spotify
© 2013 - 2025 Mike