Skip to content

Instantly share code, notes, and snippets.

View leiless's full-sized avatar
🎯
Focusing

Fishbone° leiless

🎯
Focusing
  • Shanghai, China
  • 22:20 (UTC +08:00)
View GitHub Profile
@leiless
leiless / transfer.tla
Created May 12, 2022 10:22
TLA+ PlusCal `transfer` module
---- MODULE transfer ----
EXTENDS Naturals, TLC
(* --algorithm transfer
variables alice_account = 10, bob_account = 10,
account_total = alice_account + bob_account;
process Transfer \in 1..2
variable money \in 1..20;
#include <stdio.h>
#include <string.h>
int main(void) {
// https://unicode-table.com/en/2764/
const char *s = "❤";
size_t len = strlen(s);
for (size_t i = 0; i < len; i++) {
printf("%02X", (unsigned char) s[i]);
putchar(i != len - 1 ? ' ' : '\n');
@leiless
leiless / mctop.git.diff
Last active March 14, 2022 12:24
etsy/mctop patches
diff --git a/bin/mctop b/bin/mctop
index 20da5f8..f09070e 100755
--- a/bin/mctop
+++ b/bin/mctop
@@ -23,7 +23,7 @@ sort_order = :desc
done = false
# trap most of the typical signals
-%w[ INT QUIT HUP KILL ].each do |sig|
+%w[ INT QUIT HUP ].each do |sig|
@leiless
leiless / blob_image_example.html
Last active March 12, 2022 23:42
Blob image example
<html>
<body>
<script>
fetch('https://upload.wikimedia.org/wikipedia/commons/3/31/Red-dot-5px.png')
.then(res => res.blob()) // Gets the response and returns it as a blob
.then(blob => {
// Here's where you get access to the blob
// And you can use it for whatever you want
// Like calling ref().put(blob)
@leiless
leiless / app-indicator-demo.py
Last active February 11, 2022 12:34
AppIndicator3 python3 example
#!/usr/bin/env python3
import gi
import os
gi.require_version('Gtk', '3.0')
def gi_import(name, ver):
try:
gi.require_version(name, ver)
@leiless
leiless / webview_example.go
Created December 22, 2021 08:47
Minimal webview/webview example in Golang
package main
import (
"github.com/webview/webview"
"log"
)
func webFuncInjection() {
w := webview.New(true)
defer w.Destroy()
@leiless
leiless / isal_crypto_submit_flush.cpp
Last active November 26, 2021 02:55
Bad SHA512 hash result on Linux aarch64
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdint>
#include <cassert>
#include <isa-l_crypto.h>
#include <endian.h>
#define HASH_CTX_MGR SHA512_HASH_CTX_MGR
#define HASH_CTX SHA512_HASH_CTX
@leiless
leiless / isal_crypto_submit_flush.c
Last active November 25, 2021 11:31
ISA-L Crypto MD5 submit & flush example (a single hash job)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <assert.h>
#include <isa-l_crypto.h>
#include <endian.h>
static MD5_HASH_CTX *
submit_flush(MD5_HASH_CTX_MGR *mgr, MD5_HASH_CTX *ctx, const void *buffer, HASH_CTX_FLAG flags) {
@leiless
leiless / armbian-ubuntu-podman.sh
Last active July 11, 2024 10:35
HOWTO install podman in Armbian Ubuntu
# 1. Install podman
# https://podman.io/getting-started/installation#ubuntu
. /etc/os-release
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/Release.key" | sudo apt-key add -
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y install podman
# 2. Install missing dependencies
@leiless
leiless / gen_rand_mac.sh
Created September 29, 2021 08:07
Linux shell - how to generate random MAC address
#!/bin/bash
set -eufo pipefail
#set -x
tr -dc a-f0-9 < /dev/urandom | head -c 12 | sed -r 's/(..)/\1:/g;s/:$//1'