sprite 发布的文章

daisyUI

https://daisyui.com daisyUI — Tailwind CSS Components WebdaisyUI is a plugin for Tailwind CSS. It works on all JS frameworks and doesn't need a JS bundle file. Install daisyUI as a dev dependency and use the class names just like any …

Chakra UI

https://chakra-ui.com Chakra UI - A simple, modular and accessible component … WebCreate accessible React apps. with speed. Chakra UI is a simple, modular and accessible component library that gives you the building blocks you need to build your React applications.

mantine (UI)

https://mantine.dev/

Global web icon

react-icons.github.io https://react-icons.github.io/react-icons React Icons - GitHub Pages WebReact Icons. Include popular icons in your React projects easily with react-icons, which utilizes ES6 imports that allows you to include only the icons that your project is using. …

tabler-icons

https://tabler-icons.io/

Over 4850 pixel-perfect icons for web design Free and open source icons designed to make your website or app attractive, visually consistent and simply beautiful.

Introduction to Immer

GitHub Pages https://immerjs.github.io › immer Immer (German for: always) is a tiny package that allows you to work with immutable state in a more convenient way. ‎React & Immer · ‎Using produce · ‎Supporting immer · ‎Installation

hooks

immer

https://zhuanlan.zhihu.com/p/639089491

  1. use-immer库的高级用法 下面我们将介绍use-immer库的高级用法,包括:

3.1 使用produce函数 produce函数是use-immer库中最重要的函数之一。它可以帮助我们更加方便地管理和更新JavaScript对象和数组。下面是一个简单的例子:

import { produce } from 'immer';
const state = {
  todos: [
    { id: 1, text: 'Learn React', completed: true },
    { id: 2, text: 'Learn use-immer', completed: false },
  ],
};
const nextState = produce(state, draftState => {
  draftState.todos.push({ id: 3, text: 'Learn Redux', completed: false });
});
console.log(nextState.todos);

在上面的例子中,我们使用了produce函数来更新state中的todos数组。我们可以看到,使用produce函数可以帮助我们更加方便地更新JavaScript对象和数组。


react snippets

a quick way to create a code template for a component or etc...

rcc

refs

ref is a reference to a element but ref maybe null

react-hook-form

transform several properties

const obj = {
    className: "none",
    size: 14,
    color: "red"
}

<Comp
    { ... obj }
/>

equals

<Comp
    className={obj.className}
    size={obj.size}
    color={obj.color}
/>

... means    loop the obj and set each key to the value

zod , joi , ... validation libs

import { z } from 'zod';

// create the limites
const schema = z.object({
    name: z.string().min(3, {"message":"at least 3 characters."}),
    age: z.number({invalid_type_error:"required"}).min(18) // the api shoud be mobile and ...
})

// create the  interface for data
type FormData = Formz.infer<typeof schema>;
@hookform/resolvers
const {
    register,
    handleSubmit,
    formState: {errors,isValid}
} = 
useForm<FormData>( { resolver: zodResolver(schema) } );
useEffect()

useEffect is similar to a "OnRendered" Callback when JSX modules is rendered then react call this function

finally()

the finally method will be called both succeed or failed when fetch on axios

?. optional link

seemly to swift syntax

obj?.type means obj && obj.type

Abort Signal

Mozilla Developer https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal AbortSignal - Web APIs | MDN WebAug 4, 2023 · English (US) AbortSignal. The AbortSignal interface represents a signal object that allows you to communicate with a DOM request (such as a fetch request) and abort it …

const controller = new AbortController();
const signal = controller.signal;

const url = "video.mp4";
const downloadBtn = document.querySelector(".download");
const abortBtn = document.querySelector(".abort");

downloadBtn.addEventListener("click", fetchVideo);

abortBtn.addEventListener("click", () => {
  controller.abort();
  console.log("Download aborted");
});

function fetchVideo() {
  fetch(url, { signal })
    .then((response) => {
      console.log("Download complete", response);
    })
    .catch((err) => {
      console.error(`Download error: ${err.message}`);
    });
}

Array.reduce()

Mozilla Developer https://developer.mozilla.org/.../Array/Reduce Array.prototype.reduce() - JavaScript | MDN - MDN Web … WebSep 14, 2023 · Array.prototype.reduce () Try it. The reducer walks through the array element-by-element, at each step adding the current array value to the... Syntax.

JavaScript Array filter()

WebThe filter () method creates a new array filled with elements that pass a test provided by a function. The filter () method does not execute the function for empty elements.

随着智能化在生活的方方面面深入,家电设备上的智能化需求也是在不断增长。 同时伴随着芯片行业的飞速发展、芯片的国产化进程不断推进,在家用电器上内嵌一块显示屏、并且提供智能化的设备服务已经成为一个行业趋势。

本文从需求、行业特性、技术架构几个角度试图探索、分析和预测一下家电行业的智能化趋势。


需求:智能家电的本质是什么?

科技的世俗目的是扩展人类的能力边界,而计算机则是大大降低了人脑在记忆、数据处理方面的心智成本,“智能”则是站在体验的角度,基于一个高性能设备,通过各类交互和流程设计,令计算机(设备)的使用更符合人类的直觉感观体验,能够让用户更加“随心所欲”操控计算机的概括。

a. 其智能化的程度主要体现在用户通过直觉体验能够对于设备操作的精细度以及完成复杂的组合式目标的便捷和直观程度上。

比起智能手机、汽车与家电的相似性更高,都是在可以完全通过机械操作完成设备的工作。其智能化的程度主要体现在用户通过直觉体验能够对于设备操作的精细度以及完成复杂的组合式目标的便捷和直观程度上。(这里的智能实际上是设备本身替代和减少人类思考决策和操作而形成的机器智能的感观体验,而并不是设备本身一定具有切实的AI能力)

- 阅读剩余部分 -

lv_draw_sw_img_decoded

img_decoded 是用于解码图片并且将图片绘制到指定buffer区域。

LV_ATTRIBUTE_FAST_MEM 
void lv_draw_sw_img_decoded
(
struct _lv_draw_ctx_t * draw_ctx,
const lv_draw_img_dsc_t * draw_dsc,
const lv_area_t * coords, 
const uint8_t * src_buf, 
lv_img_cf_t cf
)

/**
    struct _lv_draw_ctx_t * draw_ctx        // 绘制上下文
    const lv_draw_img_dsc_t * draw_dsc      // 图像素材绘制描述
    const lv_area_t * coords                // 绘制区(图像在output buffer上的绝对定位)
    const uint8_t * src_buf                  // 图像buffer
    lv_img_cf_t cf                          // 图像色彩格式
**/

绘制上下文中,与当前绘制图像相关的属性:

typedef struct _lv_draw_ctx_t  {
    /**
     *  Pointer to a buffer to draw into
     */
    void * buf;

    /**
     * The position and size of `buf` (absolute coordinates)
     */
    lv_area_t * buf_area;

    /**
     * The current clip area with absolute coordinates, always the same or smaller than `buf_area`
     */
    const lv_area_t * clip_area;

} lv_draw_ctx_t;

与图像本身的绘制效果相关的:

typedef struct {

    int16_t angle;
    uint16_t zoom;
    lv_point_t pivot;

    lv_color_t recolor;
    lv_opa_t recolor_opa;

    lv_opa_t opa;
    lv_blend_mode_t blend_mode : 4;

    int32_t frame_id;
    uint8_t antialias       : 1;
} lv_draw_img_dsc_t;

在进行macOS嵌入式调试的时候,用gdbserver报错 使用pyenv安装2.7之后同样无果,后使用安装包安装解决

dyld[675]: Library not loaded: /System/Library/Frameworks/Python.framework/Versions/2.7/Python
  Referenced from: <26C16900-9C5F-32FC-9593-0458A2B42E1C> /Users/mac/dev/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-gdb
  Reason: tried: '/System/Library/Frameworks/Python.framework/Versions/2.7/Python' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/System/Library/Frameworks/Python.framework/Versions/2.7/Python' (no such file), '/System/Library/Frameworks/Python.framework/Versions/2.7/Python' (no such file, not in dyld cache), '/Library/Frameworks/Python.framework/Versions/2.7/Python' (no such file)

copied from: https://blog.shahednasser.com/how-to-install-python-2-on-mac-12-3/

As of macOS 12.3+, Python 2 which was installed by default at /usr/bin/python have been removed. This can lead to a lot of issues for developers that need to use Python 2 or that use other tools that depend on it.

Install Python 2 To install Python2 again, simply download the macOS universal installer from Python's website

After downloading the installer run it to install Python 2. This will automatically install Python in /usr/local/python as well.

Test it Out You can run Python 2 in your terminal now and other tools using it will no longer have issues:

python

lvgl doc flex

lv_obj_set_layout(obj, LV_LAYOUT_FLEX)

The possible values for flex_flow are:

LV_FLEX_FLOW_ROW: Place the children in a row without wrapping
不换行的ROW

LV_FLEX_FLOW_COLUMN: Place the children in a column without wrapping

LV_FLEX_FLOW_ROW_WRAP: Place the children in a row with wrapping

LV_FLEX_FLOW_COLUMN_WRAP: Place the children in a column with wrapping

LV_FLEX_FLOW_ROW_REVERSE: Place the children in a row without wrapping but in reversed order

LV_FLEX_FLOW_COLUMN_REVERSE: Place the children in a column without wrapping but in reversed order

LV_FLEX_FLOW_ROW_WRAP_REVERSE: Place the children in a row with wrapping but in reversed order

LV_FLEX_FLOW_COLUMN_WRAP_REVERSE: Place the children in a column with wrapping but in reversed order



The possible values are:

LV_FLEX_ALIGN_START: means left on a horizontally and top vertically. (default)

LV_FLEX_ALIGN_END: means right on a horizontally and bottom vertically

LV_FLEX_ALIGN_CENTER: simply center

LV_FLEX_ALIGN_SPACE_EVENLY: items are distributed so that the spacing between any two items (and the space to the edges) is equal. Does not apply to track_cross_place.

LV_FLEX_ALIGN_SPACE_AROUND: items are evenly distributed in the track with equal space around them. Note that visually the spaces aren't equal, since all the items have equal space on both sides. The first item will have one unit of space against the container edge, but two units of space between the next item because that next item has its own spacing that applies. Not applies to track_cross_place.

LV_FLEX_ALIGN_SPACE_BETWEEN: items are evenly distributed in the track: first item is on the start line, last item on the end line. Not applies to track_cross_place.


很多时候需要对文件、文件夹进行批量处理 如果直接使用递归 -R 来做的话,一般就无法区分文件和文件夹

使用find就可以根据需要自由的查找并进行进一步处理

 find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 744 {} \;

2. 计算圆的相关数据

题中给出的r、h在最后的答案中无意义

球的体积 V = 4/3 Pi r^3 球的表面积 S = 4 Pi r^2

体积公式推导和论证 : https://www.zhihu.com/question/405287938

#include <iostream>
#include <iomanip>

using namespace std;

const float PI = 3.1415926;

int main(){

    float r,h;

    cout << "请依次输入半径和圆柱体高度." << endl;
    cin >> r >> h;

//  cout << setpreise(2) << setfixed;
    cout << setiosflags( ios::fixed ) << setiosflags( ios::right ) << setprecission( 2 );
    cout << "\n周长:" << 2*PI*r;
    cout << "\n面积:" << PI*r*r;
    cout << "\n圆球表面积:" << 4 * PI * r * r;
    cout << "\n球的体积:" << 4.0 / 3.0 * PI * r * r *r;
    cout << "\n圆柱体体积:" << PI*r*r*h;
    cout << endl;
    return 0;
}

- 阅读剩余部分 -

隐约记得之前做过一个c++的题目是判断一个数是否素数(质数) 我当时给的算法是判断 2 - x/2, 因为被除数大于 x/2 那商一定小于2,所以被除数必须大于x/2

最近看书的时候发现通用的算法是计算 2- sqrt(x) 即 根号x 这就让我产生疑问了,毋庸置疑,这个算法的效率更高,时间复杂度是logn。 那为什么到sqrt(x)就够了呢?

我反复思考总算得出了结论,这里用反证法即可:

已知 n 不是素数,且a,b是 n的两个根, a*b = n
假设 b>sqrt(n),且a>=sqrt(n)
则a*b > sqrt(n) * sqrt(n) 即 a*b > n 与条件相悖

得出若存在一个根大于sqrt(n),
那必定存在另一个小于sqrt(n)的根

与此对应的逆否命题是

若不存在小于sqrt(n)的根,则不存在大于sqrt(n)的根

根据这个证明的结论,判断是否是素数,最多只需要判断到 n 的平方根即可。

1. 使用前需要导入库

C和C++语言层面都是不提供输入输出功能的。 C使用scanf和printf这类函数用于输入输出 C++使用iostream库中的 cin、cout来进行输入输出

使用cin 导入 #include <istream> 使用cout 导入 #include <ostream> 都使用 导入 #include <iostream>

2. 输入输出流可以连续使用表达式

cin >> a >> b >> c; cout << a << b << c << endl;

3. 输入输出流自动根据上下文处理变量类型

4. 输出流 支持使用表达式

cout << a+'b' << endl;

- 阅读剩余部分 -

#include <iostream>
using namespace std;

int main()
{
    char c1,c2,c3,c4,c5;
    c1='C', c2='h', c3='i', c4='n', c5='a';
    c1+=4,  c2+=4,  c3+=4,  c4+=4,  c5+=4;
    cout << c1 << c2 << c3 << c4 << c5 << endl;
   return 0;
}

这里可以考虑将某个特定数字改写为常量、或变量

在C、C++中有一系列位运算符,在学习位运算符的时候就需要先了解反码、补码的原理。 因为位运算是按照变量在内存中所表示来进行运算的。

而计算机中,数字是按照二进制的补码进行存储的,当然(其他类型以及高级类型本质上也是数字)

二进制的原码,就是将十进制数转换为二进制。

正数的 反码、补码和原码一致

负数的 反码、补码按照以下方式转换

反码:原码符号位不变,其他位按位取反就可以得到了。 补码:反码+1就得到补码。

int a = 251
int b = -232

a的原码:00000000 11111011 a的反码:00000000 11111011 a的补码:00000000 11111011

b的反码:11111111 00010111 b的原码:10000000 11101000 b的补码:11111111 00011000

a+b = 19

使用ab的原码相加 得 10000001 11100011 即 -483 使用ab的反码相加 得 00000000 00010010 即 18 使用ab的补码相加 得 00000000 00010011 即 19

使用补码,如果从比较粗浅的角度来理解,主要是因为负数存在一个 -0,这个 -0 和“正数”中的0 冲突了,在进行加法运算的时候,-0也占了一个位置,这样就会导致,正负数相加结果和我们数学体系中的表示结果差一位,所以负数一律补1,这样就规避掉-0这个陷阱了。

“这个问题理解的时候,我觉得不要讲计算机中的数字理解位数字,实际上计算机里没有所谓的正负,只是存在了2^n中状态,而我们人类数学刚好存在一个0点,这个0点在二进制表示中,其实不应该有位置,但是又必须有,所以就会导致另外一个对称状态很尴尬。”


回到位运算

<< 左移 int a = 5; a<<=1 0000 0101->0000 1010 a=10

>> 右移 int a = 5; a>>=1; 0000 0101->0000 0010 a=2

& 与(且) int a = 5; a&=1; 0000 0101 & 0000 0001 > 0000 0001 a=1

int a = 5; a&=3; 0000 0101 & 0000 0011 > 0000 0001 a=1

|int a = 5; a|=1; 0000 0101 | 0000 0001 > 0000 0101 a=5

int a = 5; a|=3; 0000 0101 | 0000 0011 > 0000 0111 a=7

^ 异或 (不同) int a = 5; a^=1; 0000 0101 ^ 0000 0001 > 0000 0100 a=4

int a = 5; a^=3; 0000 0101 ^ 0000 0011 > 0000 0110 a=6

~ 取反 单目运算 int a = 5; ~0000 0101 > 1111 1010 (补码) 对补码进行还原 反码= 1111 1001,得到原码 = 1000 0110a= -6