8月 31

rust学习初步

算法还是使用http://www.simonzhang.net/?p=2789。

study.rs

fn check(n:u64) -> bool{
    let ll = n.to_string().len();
    let cc = String::from(n.to_string());
    let mut nn1 = 0;
    let mut nn2 = ll-1;
    while nn1 < ll{
        if cc.chars().nth(nn1) != cc.chars().nth(nn2){
            return false;
        }
        if nn2 == 0{
            break;
        }
        nn1 += 1;
        nn2 -= 1;
    }
    return true;
}

fn main() {
    let x:u64 = 10;
    let y = x.pow(7);
    let mut i = 0;
    while i <= y {
        if check(i){
            if check(i*i){
                println!("{} {}", i, i*i)
            }
        }
        i+=1;
    }
}

cargo.toml

[profile.release]
lto = true
codegen-units = 1

使用UPX -9 压缩后400k,执行1秒以内。

6月 29

python3 多CPU加速

#!env python3
# -*- coding:utf-8 -*-
# Author:      simonzhang.net
import time
from multiprocessing import Pool

def toPrint(n):
    print(n, int(time.time()))
    time.slee(0.5)

if __name__=='__main__':
    # 系统有20个CPU
    p = Pool(20)
    # 加载数据
    for i in range(60):
        p.apply_async(toPrint, args=(i,))
    # 加载完成开始执行
    p.close()
    p.join() 

5月 08

Did not receive identification string from 127.0.0.1 port 问题处理

安装frp服务ssh穿透内网,系统日志中报大量 Did not receive identification string from 127.0.0.1 port xxxx 。由于都是内网地址,所以不是攻击或扫描。此问题是由于服务自动检查穿透端口服务器是否健康引起。

代码位置
frp/client/proxy/proxy_wrapper.go 89 行

2个简单解决方案,只是缓解。

1.延长检查服务时间 frp客户端配置 ,进行延长,单位为妙
health_check_interval_s = 10

2.降低ssh日志记录级别

11月 23

3D打印机启停代码Gcode

Gcode开始和结束代码。停机回抽材料,返回原点,蜂鸣提醒。

开始

M104 S{print_temperature}
M140 S{print_bed_temperature}
M143 S270 ;喷头超出270度shutdown
M105
M109 S{print_temperature} E1
M190 S{print_bed_temperature}
M105
G21 ;metric values
G90 ;absolute positioning
M82 ;set extruder to absolute mode
M107 ;start with the fan off
G28 X0 Y0 ;move X/Y to min endstops
G28 Z0 ;move Z to min endstops
G1 Z15.0 F{travel_speed} ;move the platform down 15mm
G92 E0 ;zero the extruded length
G1 F200 E3 ;extrude 3mm of feed stock
G92 E0 ;zero the extruded length again
G1 F{travel_speed}
;Put printing message on LCD screen
M117 Printing…

结束代码

G91
G1 Z+5.0 E-5 F200 ;Z上移5mm 回抽10mm
G90
G28 X0 Y0
M300 S100 P1000 ;end sound
M104 S0 ;extruder heater off
M140 S0 ;heated bed heater off (if you have it ;retract the filament a bit before lifting the nozzle, to release some of the pressure
M106 S0
M84 ;steppers off
G90 ;absolute positioning
;{profile_string}

6月 02

echarts 在图片上做标注

主要思路:1、先有背景图,2、有刻度,3、隐藏X、Y轴显示,4、隐藏直线显示,5、进行标注。使用echarts实现,代码如下

var img = new Image(); //新建对象
img.src="http://pic.sc.chinaz.com/files/pic/pic9/201708/zzpic6006.jpg";

option = {
    // 背景
    backgroundColor: {
        type: "pattern",
        repeat: "repeat",
        image: img,
    },
    title: {
        text:"XXXXX"
    },
    xAxis: {
        show : false,
        data: [1,2,3,4,5,6,7,8,9]
    },
    yAxis: {
        show : false,
    },
    series: [{
        type:"line",
        data: [1,2,3,4,5,6,7,8,9],
        //隐藏直线
        showSymbol: false,
        lineStyle: {
            width: 0,
            color: 'rgba(0, 0, 0, 0)'
        },
        // 标注气泡
        markPoint: {
                data: [
                    {name: 'y', value:"嘴", xAxis:3, yAxis: 1.5},
                    {name: 'z', value:"眼睛", xAxis: 1, yAxis: 6},
                ]
            },
        },
    ]
};

随便找了张图片,效果如下: