My Learning Journal

This is where I will post about my journey learning tech.

2025

识别cavas指纹是否被篡改

工作量证明方法——要求用户绘制画布并验证某些已知像素的数值.

  生成一个特定颜色的画布,并验证特定像素的数值是否符合预期的。下面的代码片段展示了一个简单的示例,我们将画布填充为 rgba(0, 127, 255, 1)。然后,我们对每个像素进行迭代,验证 r、g、b、a 的分量是否具有期望值(因此代码中使用%4)。

示例代码:

var canvas = document.createElement("canvas");
canvas.height = size;
canvas.width = size;
var context = canvas.getContext("2d");
context.fillStyle = "rgba(0, 127, 255, 1)";
var pixelValues = [0, 127, 255, 255];
// We apply the color rgba(0, 127, 255, 1) to the whole canvas
context.fillRect(0, 0, canvas.width, canvas.height);
var pixels = context.getImageData(0, 0, canvas.width, canvas.height).data;
for (var i = 0; i < pixels.length; i += 1) {
    if (pixels[i] !== pixelValues[i % 4]) {
        // we test if the pixel has the expected value
        // If that's not the case it means the canvas value has been modified
        console.log('Canvas has been overridden!')
    }
}

使用kuroshiro库给日文汉字附加假名

Welcome to my new blog about learning Astro! Here, I will share my learning journey as I build a new website.

What I’ve accomplished

  1. Installing Astro: First, I created a new Astro project and set up my online accounts.

  2. Making Pages: I then learned how to make pages by creating new .astro files and placing them in the src/pages/ folder.

  3. Making Blog Posts: This is my first blog post! I now have Astro pages and Markdown posts!

What’s next

I will finish the Astro tutorial, and then keep adding more posts. Watch this space for more to come.

It wasn’t always smooth sailing, but I’m enjoying building with Astro. And, the Discord community is really friendly and helpful!

three.js简单代码解析

实现一个时间线

image

样式参考:Long Luo’s Life Notes

​ 实现方法有很多种,这里只给出此博客所用的方法。

  以图中的样式为例,大号⚪代表年份,小号⚪代表单个文章,淡淡的竖线,时间轴由这些元素组成

HTML结构

timeline
::before
	year
		marker //圆点
		//此处输入自定义文字
	posts
		post-link
			marker //圆点
			content
				//此处输入自定义文字

圆形

圆形由svg实现:

<svg
    class="marker"
    //定义css类名
    xmlns="http://www.w3.org/2000/svg"
    //声明命名空间
    width="12"
    height="12"
    //图形长宽
>
    <circle cx="6" cy="6" r="6"></circle>
    //circle是一个svg的圆形元素
    //cx,cy:圆心的x,y坐标
    //r:半径
</svg>

数轴

数轴使用了伪元素,伪元素属于css,可以在一个元素中创建拥有特殊性质的元素,伪元素的一种典型的用法就是生成线条

.timeline::before {
    content: "";
	//必须设置content,否则元素不会显示
    position: absolute;
    //定位上下文
    bottom: -20px;
    //底面移动-20px,向下微调20px
    height: 100%;
    //长度为整个元素块
    width: 2px;
    //宽度
    background-color: rgb(240, 240, 240);
    //设置线条颜色
}

至此,一个简单的时间轴的骨架就完成了,接下来就是添加css代码调整格式,由于数轴直接插入示例代码就能用,相对简单,这边就不进行演示了。

image2

首先,可以看到有几点问题

  1. 竖线横跨了整个窗口,这是因为将伪元素的position设置了 absolute,默认会向上查找最近的static 定位的元素,我们需要将timeline元素作为定位参考
  2. 小圆点没有和文字对齐
  3. 小圆点被竖线覆盖了

以下是示例代码

//1.
.timeline{
    position:relative;
}
//2.
.post-link {
    display: flex;
    //可以让圆点和文字在同一行
    align-items: baseline;
	//这种对齐方式可以稍微让圆点回正一点
}
.post-link .marker {
    position: relative;
    //建立一个新的层叠上下文,让圆点覆盖竖线
    left: -2px;
    bottom: -2px;
    //对圆点位置进行微调
}

同理,对其他部分也进行设置,这个时间轴就建好了,剩下的就是对其他元素进行样式优化就好了

导出onenote for windows10中的笔记

import datetime
from turtle import title
import pyperclip
import win32gui
from pywinauto import Application
from pywinauto import mouse
from pywinauto import keyboard
import get_excel_rows_as_dict

def get_window_handle(window_title):
    """
    获取窗口句柄。

    参数:
        window_title (str): 窗口标题。

    返回:
        int: 窗口句柄。如果未找到窗口,返回 None。
    """
    hwnd = win32gui.FindWindow(None, window_title)
    if hwnd == 0:
        print(f"未找到窗口:{window_title}")
        return None
    return hwnd


def connect_to_window(hwnd):
    """
    连接到指定窗口。

    参数:
        hwnd (int): 窗口句柄。

    返回:
        pywinauto.application.WindowSpecification: 窗口对象。
    """
    try:
        app = Application(backend='uia').connect(handle=hwnd)
        window = app.window(handle=hwnd)
        return window
    except Exception as e:
        print(f"连接窗口失败:{e}")
        return None


def select_text(window, target_title, static_control):
    """
    获取选中文本。

    参数:
        window: 窗口对象。
        target_title (str): 目标控件的标题。
        static_control (str): 静态控件的名称。

    返回:
        str: 选中的文本。如果获取失败,返回 None。
    """
    try:
        # 定位目标控件
        target = window.child_window(title=target_title, control_type="ListItem")
        if not target.exists():
            print(f"未找到目标控件:{target_title}")
            return None

        # 定位静态控件
        static = target.child_window(best_match=static_control)
        if not static.exists():
            print(f"未找到静态控件:{static_control}")
            return None
        # 获取控件位置并点击
        static.click_input()
        
        # rect = static.rectangle()
        # x, y = rect.left + 40, rect.bottom - 10
        # mouse.click(coords=(x, y))
        # mouse.click(coords=(x, y))

    #     # 复制文本
    #     keyboard.send_keys('^c')
    #     selected_text = pyperclip.paste()
    #
    #     # 如果剪贴板为空,尝试发送回车键
    #     if not selected_text:
    #         keyboard.send_keys('~')
    #         selected_text = pyperclip.paste()
    #
    #     return selected_text
    except Exception as e:
        print(f"获取选中文本失败:{e}")
        return None


def main():
    # 窗口标题
    window_title = "资产管理"

    # 获取窗口句柄
    hwnd = get_window_handle(window_title)
    if not hwnd:
        return

    # 连接到窗口
    window = connect_to_window(hwnd)
    if not window:
        return

    # 获取excel内容
    data_dict = get_excel_rows_as_dict.get_rows_as_dict()

    if not data_dict:
        raise ValueError("错误:未获取到excel数据,程序终止运行。")
    # 自动获取子控件列表
    list_items = window.descendants(control_type="ListItem")
    # print(list_items)
    # 选中单元格,准备输入
    target_title = "198"  # 目标控件的标题
    static_control = "Static5"  # 静态控件的名称
    select_text(window, target_title, static_control)

    fin = list()

    for item in list_items[197:]:
        fin.append(item.children()[1].window_text())

    # 根据控件数量,录入数据
    for i in fin:
        # 比对数据
        # print("获取的字典数据:")
        # if i not in data_dict:
        #     keyboard.send_keys("{DOWN}")  # 如果 i 不是 data_dict 的 key,则跳过此次循环
        #     continue
        # keyboard.type_keys(str(data_dict[i][2]))
        # keyboard.send_keys('~')
        # if (data_dict[i]):
        print(i)
        print(data_dict[i])
        for o in data_dict[i]:
            # print(o)
            # 获取选中文本
            pyperclip.copy("")
            keyboard.send_keys('^c')
            selected_text = pyperclip.paste()
            # print(selected_text)
            if selected_text == o:
                keyboard.send_keys('~')
            elif get_excel_rows_as_dict.pd.isna(o):
                # 输入value值
                keyboard.send_keys('~')
            elif isinstance(o, datetime.datetime):
                temp = str(o).split(" ")[0]
                # print(temp)
                keyboard.send_keys(temp)
                keyboard.send_keys('~')
                # print(str(o))
            # elif get_excel_rows_as_dict.pd.isna(selected_text):
            elif selected_text == "":
                # print(str(o))
                keyboard.send_keys(str(o))
                keyboard.send_keys('~')
            else:
                keyboard.send_keys('~')

if __name__ == "__main__":
    main()

基于robocopy实现从网络位置复制文件到本地