Skip to content

Instantly share code, notes, and snippets.

View haolian9's full-sized avatar
🐢
make it work, make it right

高浩亮 haolian9

🐢
make it work, make it right
View GitHub Profile
@haolian9
haolian9 / redis_ping.lua
Created April 27, 2023 06:29
send ping to redis from nvim's lua runtime
local uv = vim.loop
local sock = assert(uv.new_pipe())
uv.pipe_connect(sock, "/run/user/1000/redis.sock", function(err) assert(err == nil, err) end)
uv.read_start(sock, function(err, data)
if err then
print("read error", err)
elseif data then
print("read data", data)
@haolian9
haolian9 / main.lua
Last active May 26, 2023 10:51
interactive sudo for nvim
---@diagnostic disable: unused-local
--design choices/limits
--* sudo runs in a tty process
--* sudo should run in background
--* prompt user to enter his password when needed
--* singleton
--* sync but not blocking nvim
--
--supported forms:
@haolian9
haolian9 / ParkingLot.zig
Created July 10, 2022 14:29 — forked from kprotty/ParkingLot.zig
Small & Fast synchronization primitives for Zig
pub fn ParkingLot(comptime Config: type) type {
return struct {
pub const Lock: type = Config.Lock;
pub const Event: type = Config.Event;
pub const nanotime: fn() u64 = switch (@hasDecl(Config, "nanotime")) {
true => Config.nanotime,
@haolian9
haolian9 / lsmnts.zig
Created June 20, 2022 03:28
list mount points
/// mntpoints come from fstab
const std = @import("std");
const mem = std.mem;
const linux = std.os.linux;
const assert = std.debug.assert;
const os = std.os;
const c_fstab = @cImport(@cInclude("fstab.h"));
allocator: mem.Allocator,
@haolian9
haolian9 / xclip
Created March 8, 2022 16:01
xsel wrapper of xclip for [pass](https://www.passwordstore.org)
#!/usr/bin/env python3
import os
import sys
def as_xsel_args():
"""only supports xclip options that are used by pass
* xclip -selection "$X_SELECTION"
@haolian9
haolian9 / asyncrun.lua
Last active February 22, 2022 12:26
a wrapper of asyncrun that respects modeline-like setting in file
-- inlinecmd
-- b:asyncrun_plaincmd
local M = {}
local inlinecmd_magic = "# asyncrun: "
local plaincmd_varname = "asyncrun_plaincmd"
local find_inlinecmd = function(bufnr)
local _reversed_lines = function(high)
@haolian9
haolian9 / server.nim
Last active February 21, 2022 13:05
a simple async chat server in nim
import std/[asyncdispatch, asyncnet, nativesockets, asyncfutures]
import std/[tables, deques]
type Nursery = object
tasks: seq[Future[void]]
proc startSoon(self: ref Nursery, fut: Future[void]) =
asyncCheck fut
self.tasks.add fut
@haolian9
haolian9 / are_threre_race_conditions_in_swoole_coroutines.php
Last active August 31, 2021 09:37
ensure no race condition in swoole coroutines
<?php
# Swoole\Coroutine::enableScheduler();
Co\run(function () {
$flag = 1;
go(function() use(&$flag) {
assert($flag == 1);
$flag += 1;
@haolian9
haolian9 / main.py
Created July 7, 2021 06:04
trio version blessed.Terminal.inkey
#!/usr/bin/env python3
import os
import trio
from trio.lowlevel import FdStream
from blessed import Terminal
from blessed.keyboard import Keystroke, resolve_sequence
@haolian9
haolian9 / .tmux.conf
Created June 12, 2021 14:49
interactive tmux resize-pane
# resize pane
# take a look at `-i` option of command-prompt
bind R command-prompt -i -p 'resize-pane' 'run-shell "~/.scripts/:resize %%"'