Skip to main content

· One min read

install

apk add sqlite lua-sql-sqlite3

crud

local sqlite3 = require "luasql.sqlite3"

-- 创建一个 SQLite 环境
local env = sqlite3.sqlite3()

-- 打开内存数据库
local db = env:connect("test.db")

-- 创建一个示例表
db:execute("CREATE TABLE test (id INTEGER PRIMARY KEY, content)")
db:execute("INSERT INTO test VALUES (1, 'Hello, World!')")
db:execute("INSERT INTO test VALUES (2, 'Lua with SQLite3')")

-- 查询并输出数据
local cursor = db:execute("SELECT * FROM test")

local row = cursor:fetch({}, "a")
print(row)
while row do
print(string.format("Row %d: %s", row.id, row.content))
row = cursor:fetch(row, "a")
end

-- 关闭游标和数据库连接
cursor:close()
db:close()
env:close()

· One min read

intro

# install
npm i -g @slidev/cli

# open
slidev test.md
# http://localhost:3030/

cli

  • dev: "slidev example.md",
  • build: "slidev build example.md",
  • export: "slidev export example.md",
  • screenshot: "slidev export example.md --format png"

demo file

---
theme: default
---

# Slidev

Hello World

---

# Page 2

Directly use code blocks for highlighting

```ts
console.log('Hello, World!')

Page 3


· One min read

ossfs

wget https://gosspublic.alicdn.com/ossfs/ossfs_1.91.1_ubuntu22.04_amd64.deb
dpkg -i ossfs_1.91.1_ubuntu22.04_amd64.deb

dpkg --configure -a
apt-get -f install

echo cert:key > /etc/passwd-ossfs
chmod 600 /etc/passwd-ossfs

s3fs madex-test /www/minio-oss -o passwd_file=/etc/passwd-ossfs -o url=http://oss-cn-shanghai-internal.aliyuncs.com
umount /www/minio-oss

· 2 min read

demo1

docker run -it apache/spark:python3 /opt/spark/bin/pyspark

# >>> spark.range(1000 * 1000 * 1000).count()

job

docker run --restart=unless-stopped -it -d --name spark -p 4040:4040 -v $(pwd):/app -e TZ=utc-8 apache/spark:python3 tail -f
docker run --restart=unless-stopped -it -d --name spark -p 4040:4040 -v $(pwd):/app -e TZ=utc-8 wolanx/spark /opt/spark/bin/spark-submit /app/test.py

# add jars
cd /opt/spark/jars
wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.25/mysql-connector-java-8.0.25.jar
pip install requests
# spark-submit --jars /opt/spark/jars/mysql-connector-java-8.0.25.jar /app/test.py

docker exec -it --user=root spark bash
docker exec -it spark /opt/spark/bin/spark-submit /app/test.py

test.py

import ast
import time
from datetime import datetime

import requests
from pyspark.sql import SparkSession, SQLContext
from pyspark.sql.functions import col

spark = SparkSession.builder.getOrCreate()

df = (
spark.read.format("jdbc")
.option("url", "jdbc:mysql://xxx:3306/xxx")
.option("dbtable", "xxx")
.option("user", "xxx")
.option("password", "xxx")
.load()
)
print(df.columns)


def write_to_influxdb(data):
# print(data)
# return
url = "https://ts-xxx.influxdata.tsdb.aliyuncs.com:8086/write?db=xxx&u=xxx&p=xxx&precision=s"
headers = {'Content-Type': 'text/plain'}
r = requests.post(url, data=data, headers=headers)
print(r.text)


def process_row(row):
rowMap: dict = ast.literal_eval(row['data'].replace('nan', 'None').replace(' _', '\\ _'))
fields = ','.join([f"{k}={v}" for k, v in rowMap.items() if v is not None])
write_to_influxdb(f"sensor_0s,SNO=#device({row['device_id']}).perf {fields}")


def doRun():
while True:
current_second = int(time.time()) % 60

if current_second == 0:
rDt = datetime.now().replace(second=0)
df2 = df.where((df.d == rDt.day) & (df.his == rDt.strftime("%H:%M:%S"))).orderBy(
col("id").desc()) # .limit(5)
# print(df2.show())

df2.foreach(process_row)

time.sleep(1)


doRun()

cluster

spark-shell --master local

· One min read

config

:help config

# windows
Unix ~/.config/nvim/init.vim (or init.lua)
Windows ~/AppData/Local/nvim/init.vim (or init.lua)
|$XDG_CONFIG_HOME| $XDG_CONFIG_HOME/nvim/init.vim (or init.lua)

git clone https://github.com/nshen/learn-neovim-lua.git

· One min read

2023-03-06 grundfos java17-graalvm22

FROM debian:11-slim
LABEL maintainer="wolanx<82540776@qq.com>"

RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list \
&& sed -i 's/security.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list

# https://github.com/graalvm/graalvm-ce-builds/releases
# https://github.com/graalvm/container/raw/master/community/gu-wrapper.sh /usr/local/bin/gu
# https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-22.3.1/graalvm-ce-java17-linux-amd64-22.3.1.tar.gz graalvm-ce-java17-linux-amd64-22.3.1.tar.gz
ADD graalvm-ce-java17-linux-amd64-22.3.1.tar.gz /opt/
ADD gu-wrapper.sh /opt/
RUN mv /opt/gu-wrapper.sh /usr/local/bin/gu && chmod +x /usr/local/bin/gu

ENV LANG=en_US.UTF-8
ENV JAVA_HOME=/opt/graalvm-ce-java17-22.3.1
ENV PATH="$PATH:$JAVA_HOME/bin"

RUN apt-get update -y && \
apt-get install -y procps net-tools iputils-ping htop gcc curl wget ca-certificates \
fontconfig

ADD https://gfdcc-production-profile.oss-cn-shanghai.aliyuncs.com/profile/fonts/SourceHanSansCN-Normal.ttf /usr/share/fonts/truetype/wolanx/
ADD https://gfdcc-production-profile.oss-cn-shanghai.aliyuncs.com/profile/fonts/SourceHanSansCN-Bold.ttf /usr/share/fonts/truetype/wolanx/

CMD java -version

# docker build -t wolanx/java .

2021-03-13 google jib plugin

plugins {
id 'com.google.cloud.tools.jib' version '3.3.0'
id 'java'
}
jib {
from {
image = 'openjdk:17-slim'
}
to {
image = 'xxxx'
// tags = [version.toString()]
}
container {
mainClass = 'com.wolanx.proxy.edierp.EdiApplication'
ports = ['22100']
format = 'OCI'
creationTime = 'USE_CURRENT_TIMESTAMP'
}
}

· One min read

cuda install

# https://developer.nvidia.com/cuda-11-6-0-download-archive?target_os=Linux&target_arch=x86_64&Distribution=Debian&target_version=11&target_type=deb_local
wget https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda-repo-debian11-11-6-local_11.6.0-510.39.01-1_amd64.deb
dpkg -i cuda-repo-debian11-11-6-local_11.6.0-510.39.01-1_amd64.deb
apt-key add /var/cuda-repo-debian11-11-6-local/7fa2af80.pub
add-apt-repository contrib
apt-get update
apt-get -y install cuda # error

wget http://ftp.de.debian.org/debian/pool/contrib/g/glx-alternatives/update-glx_1.2.1~deb11u1_amd64.deb
wget http://ftp.de.debian.org/debian/pool/contrib/g/glx-alternatives/glx-alternative-mesa_1.2.1~deb11u1_amd64.deb
wget http://ftp.de.debian.org/debian/pool/contrib/n/nvidia-support/nvidia-installer-cleanup_20151021+13_amd64.deb
wget http://ftp.de.debian.org/debian/pool/contrib/g/glx-alternatives/glx-diversions_1.2.1~deb11u1_amd64.deb
wget http://ftp.de.debian.org/debian/pool/contrib/g/glx-alternatives/glx-alternative-nvidia_1.2.1~deb11u1_amd64.deb

apt-get -y install cuda
apt-get install linux-headers-$(uname -r) # !!!
reboot # !!!

conda install

apt-get install linux-headers-$(uname -r) # !!!
curl -O https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh
sh Anaconda3-2022.10-Linux-x86_64.sh
# /etc/conda
# conda install pytorch torchvision torchaudio pytorch-cuda=11.6 -c pytorch -c nvidia
# conda install cuda -c nvidia

conda update

conda -V
conda update -n base conda
conda update --all
conda install python=3.11

uninstall

conda install anaconda-clean
rm -rf /etc/conda

apt-get remove --purge '^nvidia-.*'
apt-get remove --purge '^libnvidia-.*'
apt-get remove --purge '^cuda-.*'

apt-get install linux-headers-$(uname -r)

check tool

lspci | grep -i nvidia # 查看PCI设备

# 查看硬件信息
apt-get install lshw
lshw -numeric -C display # 没有 unclaimed

cat /proc/driver/nvidia/version # 检查驱动版本

nvidia-smi

· 5 min read

install

# https://luabinaries.sourceforge.net/download.html
apk add --no-cache lua5.4
mv /usr/bin/lua5.4 /usr/bin/lua

demo

hvac pump

--lua hvac.lua a1

--for k, v in pairs(arg) do
-- print(k, v)
--end

local name = arg[1] or "b6"

local ts = os.time()
local hour = tonumber(os.date("%H"))
local minute = tonumber(os.date("%M"))

-- 24小时等间数据
local dataArr = {
a0 = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
-- 制冷机 制冷量 (kW) 冷冻水进水温度 (摄氏度) 冷冻水出水温度(摄氏度) 冷冻水温差 (摄氏度) 散热量 (kW) 冷却水进水温度 冷却水出水温度 冷却水温差 电机功率(W)
a1 = { 0, 0, 0, 0, 208250, 833000, 2082500, 3748500, 5622750, 7288750, 7996800, 8121750, 6539050, 6247500, 7038850, 8163400, 7996800, 7580300, 6664000, 5081300, 3165400, 1999200, 999600, 208250 },
a2 = { 26.70, 26.70, 26.70, 26.70, 6.55, 6.83, 7.47, 8.35, 9.25, 10.09, 10.48, 10.59, 9.71, 9.60, 10.01, 10.57, 10.46, 10.22, 9.78, 8.97, 8.00, 7.47, 6.92, 6.59 },
a3 = { 26.70, 26.70, 26.70, 26.70, 6.44, 6.41, 6.42, 6.46, 6.41, 6.42, 6.45, 6.49, 6.41, 6.45, 6.46, 6.46, 6.43, 6.40, 6.42, 6.41, 6.41, 6.46, 6.41, 6.48 },
a4 = { 0, 0, 0, 0, 0.105, 0.42, 1.05, 1.89, 2.835, 3.675, 4.032, 4.095, 3.297, 3.15, 3.549, 4.116, 4.032, 3.822, 3.36, 2.562, 1.596, 1.008, 0.504, 0.105 },
a5 = { 0, 0, 0, 0, 260312.5, 1041250, 2603125, 4685625, 7028437.5, 8776250, 9596160, 9746100, 7846860, 7448942.308, 8342340.741, 9703664.151, 9602583.133, 9264811.111, 8250666.667, 6335941.975, 3956750, 2499000, 1249500, 260312.5 },
a6 = { 26.7, 26.7, 26.7, 26.7, 22.5, 23.1, 23.9, 24.7, 25.3, 25.7, 25.98, 26.1, 26.18, 26.3, 26.26, 26.14, 25.98, 25.78, 25.5, 25.18, 24.54, 24.02, 23.18, 22.5 },
a7 = { 26.7, 26.7, 26.7, 26.7, 22.61, 23.56, 25.04, 26.76, 28.39, 29.56, 30.20, 30.38, 29.63, 29.57, 29.93, 30.41, 30.20, 29.85, 29.13, 27.97, 26.28, 25.12, 23.73, 22.61 },
a8 = { 0, 0, 0, 0, 0.11, 0.46, 1.14, 2.06, 3.09, 3.86, 4.22, 4.28, 3.45, 3.27, 3.67, 4.27, 4.22, 4.07, 3.63, 2.79, 1.74, 1.10, 0.55, 0.11 },
a9 = { 0, 0, 0, 0, 52062.50, 208250.00, 520625.00, 937125.00, 1405687.50, 1487500.00, 1599360.00, 1624350.00, 1307810.00, 1201442.31, 1303490.74, 1540264.15, 1605783.13, 1684511.11, 1586666.67, 1254641.98, 791350.00, 499800.00, 249900.00, 52062.50 },
-- 冷冻水泵 水泵出口流量 (m3/h) 运行状态 水泵进口压力 水泵出口压力 扬程 电机功率 (W)
b1 = { 0, 0, 0, 0, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700, 1700 },
b2 = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
b3 = { 0, 0, 0, 0, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3, 2.3 },
b4 = { 0, 0, 0, 0, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82, 4.82 },
b5 = { 0, 0, 0, 0, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2, 25.2 },
b6 = { 0.00, 0.00, 0.00, 0.00, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80, 194350.80 },
-- 冷却水泵 水泵出口流量 (m3/h) 运行状态 水泵进口压力 水泵出口压力 扬程 电机功率
c1 = { 0, 0, 0, 0, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950, 1950 },
c2 = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
c3 = { 0, 0, 0, 0, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34 },
c4 = { 0, 0, 0, 0, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45, 2.45 },
c5 = { 0, 0, 0, 0, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1, 21.1 },
c6 = { 0.00, 0.00, 0.00, 0.00, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74, 193097.74 },
}
local dataL = dataArr[name][hour]
local dataR = dataArr[name][hour + 1]

local ret = dataL + (dataR - dataL) * (minute / 60)
local bias = math.random(-50, 50) / 1000
ret = ret * (1 + bias)

-- 排除离散
if (name == "a0" or name == "b2" or name == "c2") then
ret = dataL
end

--print(name)
--print(hour .. ":" .. minute, "(" .. dataL .. ', ' .. dataR .. ")")
print(string.format("%.2f", ret))