zhimoe

the craft of programming


  • 首页

  • 归档

  • 编程

  • 翻译

  • 项目

  • 关于

  • 搜索

Scala Python 文件读取跳过转义字符

时间: 2020-06-04   |   分类: 编程   | 字数: 358 字 | 阅读: 1分钟

在文件读取的时候,会遇到非法转义字符,导致文件按行读取失败.此时可以通过忽略转义字符来解决.本文记录了scala和python的方法.

背景

有50G的服务器日志,拆分为几千个txt文件,编码是utf8,使用scala和python按行处理:

scala

def main(args: Array[String]): Unit = {
  for (line <- Source.fromFile("./txt1.log","UTF8").getLines()) {
    if (line.contains("ABC")) {
      //do something      
    }
  }
}
阅读全文 »

Matplotlib图例中文乱码解决方案

时间: 2020-05-01   |   分类: 编程   | 字数: 419 字 | 阅读: 1分钟

很久以前写的一个答案,四年来一直有人评论感谢,说只有我的方法是有效的.非常意外也很高兴. 也放到博客中里备份吧. zhihu.com

# https://www.zhihu.com/question/25404709/answer/67672003
import matplotlib.font_manager as fm
# 微软雅黑,如果需要宋体,可以用simsun.ttc
myfont = fm.FontProperties(fname='C:/Windows/Fonts/msyh.ttc')
# Linux字体在"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", 
# 需要先安装字体">sudo apt install fonts-noto-cjk -y"
# MacOS中文字体文件在"/System/Library/Fonts/PingFang.ttc"
# Win10,Linux已测试,MacOS未验证

import matplotlib.pyplot as plt

plt.clf()  # 清空画布
plt.plot([1, 2, 3], [4, 5, 6])
plt.xlabel("横轴",fontproperties=myfont)
plt.ylabel("纵轴",fontproperties=myfont)
plt.title("pythoner.com",fontproperties=myfont)
plt.legend(['图例'],prop=myfont)
plt.show()

Rust Ownerships Lifetimes教程

时间: 2020-02-22   |   分类: 编程   | 字数: 1135 字 | 阅读: 3分钟

some notes on rust ownership,reference,string and &str, and lifetimes

阅读全文 »

SpringBoot应用和Rust应用的Dockerfile最佳实践

时间: 2020-02-03   |   分类: 编程   | 字数: 1515 字 | 阅读: 4分钟

记录spring boot和rust项目的Dockerfile的最佳实践.

spring boot应用Dockerfile

spring.io提供了一个boot应用的Dockerfile指导. 不过有个问题,这个Dockerfile使用的maven是项目源码里面copy过去的.在一般企业项目中这么做显然不规范,直接使用maven基础镜像更合理.

阅读全文 »

Docker CMD ENTRYPOINT区别

时间: 2020-02-02   |   分类: 编程   | 字数: 1098 字 | 阅读: 3分钟

记录docker中exec form和shell form的区别,CMD和ENTRYPOINT区别,以及最佳实践.

exec form VS shell form

# exec form
<instruction> ["executable", "param1", "param2", ...]

# shell form
<instruction> <command>
阅读全文 »
1 2 3 4 5 6 7 8
zhimoe

zhimoe

Captain your own Ship.

61 日志
4 分类
38 标签
RSS 订阅
GitHub ZhiHu
书签
  • 可视化学习Git
  • 美团技术团队
  • 艺术绘画
  • 500px
  • RustCheatsheet
  • 谷歌机器学习课程
标签云
  • Code
  • Java
  • Scala
  • Python
  • Rust
  • Spring
  • Docker
  • Aop
  • Aurulent
  • Cheatsheet
© 2010 - 2022 zhimoe
0%