ITeye博客

2020 年文章归档

共 60 篇文章

计算工作日期的java工具类

import org.apache.commons.collections.CollectionUtils; import org.joda.time.DateTime; import org.joda.time.DateTimeConstants; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.…

2020-12-31 10:55 · java · 经验 · utils

java的四舍五入

参考文章: https://www.cnblogs.com/chenssy/p/3366632.html public static void main(String[] args) { BigDecimal d = new BigDecimal(100000); //存款 BigDecimal r = new BigDecimal(0.001875*3); //利息 BigDecimal i = d.multiply(r).setScale(2,RoundingMode.HALF_EVEN); //使用银行家算法 System.out.println("季利息是:"+i); } Outpu…

2020-12-30 11:59 · java · 经验

存储单位工具类(来自于hadoop)

/** * 存储单位工具类 * @ClassName: StorageUnit * @author kanpiaoxue * @version 1.0 * @CreateTime: 2020/12/25 17:25:12 * @Description: * 来自于:https://github.com/apache/hadoop/blob/trunk/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/StorageUnit.java */ import java.math.BigDecimal; …

2020-12-25 17:30 · java · hadoop · utils

guava生成字符串和文件的MD5

// 计算字符串MD5 String stringMD5 = Hashing.md5().hashString("helloWorld").toString(); // 计算文件MD5 File file = new File("hello.txt"); String fileMD5 = Files.asByteSource(file).hash(Hashing.md5()).toString(); 参考guava的hash public class HashTest { private static final String INPUT = "hello, world"; public v…

2020-12-22 20:58 · java · MD5 · guava

eclipse下载插件过慢问题解决:代理服务器

点击 Preferences –> Install/Update –> Available Software Sites 在这个界面,将默认网站修改为国内镜像站:即把所有的http://download.eclipse.org 改为 http://mirrors.ustc.edu.cn/eclipse

2020-12-18 11:28 · eclipse · 经验 · 非技术

Mapped Diagnostic Context (MDC)

Mapped Diagnostic Context (MDC) 针对 MDC功能,目前只有logback 以及 log4j 支持。 相关文章: https://www.baeldung.com/mdc-in-log4j-2-logback http://logback.qos.ch/manual/mdc.html https://www.jianshu.com/p/3fa7e7726fbb https://ketao1989.github.io/2015/04/29/LogBack-Implemention-And-Slf4j-Mdc/ Let's now use the SLF4J's f…

2020-12-14 17:39 · log · slf4j · log4j

HBaseUtils(HbaseTemplate)工具类

import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Result; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org…

2020-12-10 15:38 · java · hbase

hbase的client的超时参数设置

两篇不错的文章: http://hbasefly.com/2016/06/11/hbase-client-2 https://www.sohu.com/a/331844681_315839

2020-12-02 20:51 · java · hbase

jdk8的JVM的Metaspace设置

从JDK8开始,PermSize的配置被废弃,改为Metaspace,如下: -XX:MetaspaceSize=200m -XX:MaxMetaspaceSize=200m

2020-12-02 11:47 · java · JVM

Linux下端口被占用解决

1、查找被占用的端口: netstat -tln |grep port 2、查看端口被哪个进程占用 lsof -i :port 3、通过PID查找被占用的java进程 jps -lv|grep PID 4、如果是非java进程占用,可用查找进程 ps -ef|grep PID

2020-12-01 15:24 · Linux · 经验 · shell

得到list指定元素前面一个位置的元素

得到list指定元素前面一个位置的元素 public static <T> Optional<T> findPrevious(List<T> list, T e) { Preconditions.checkNotNull(list, "list is null"); Preconditions.checkNotNull(e, "element is null"); if (CollectionUtils.isEmpty(list)) { return Optional.empty(); } int index = list.indexOf(e); ListIterator<T> iterat…

2020-08-25 18:41 · java · 经验 · jdk · 常用java类

item2多窗口同时操作

使用 iTerm2 时打开了多个窗口,需要在每个窗口依次执行命令。 其实,iTerm2 支持向多窗口(当前打开的所有窗口)同时输入相同的指令。只需要输入快捷键 ⌘(command) + ⇧(shift) + i。默认会跳出告警提示窗口: 可以勾选 Suppress this message permanently 取消告警,并 OK 确认。这时每个窗口右上角都会出现图标表示当前已激活向所有窗口输入指令。 关闭该功能的方式是再次输入快捷键 ⌘(command) + ⇧(shift) + i 即可。 参考资料: https://jacoobwang.github.io/2018/06/28/It…

2020-08-25 15:11 · 经验 · mac · item2

zeppelin的docker启动方式

docker run --rm -ti -p 9080:8080 -e ZEPPELIN_ADDR=0.0.0.0 --name zeppelin apache/zeppelin:0.8.2 匿名登录的方式: docker run -tid -p 9080:8080 -e ZEPPELIN_ADDR=0.0.0.0 --name zeppelin apache/zeppelin:0.8.2 访问地址: http://localhost:9080

2020-08-20 16:02 · 经验 · zeppelin

python的sys.exit()的0-255问题

最近写了一个python脚本用到了sys.exit(exit_code) ,遇到一个奇怪的问题。当exit_code=256的时候,预期python调用sys.exit(exit_code) 之后退出进程之后的退出码应该是256,可实际情况退出码是0. 这引发我这边的程序异常,判断任务是运行成功的。 问题的根节就在:sys.exit(256) 的时候python的退出码是0. 我又验证了一下,sys.exit(exit_code) 中的exit_code是256的整数倍的时候,python进程退出码全部是0. 找了一些资料,发现这个是python自身的限制问题。 如下的资料: http://…

2020-08-14 16:42 · python · 经验 · shell

如何使用Python SimpleHTTPServer提供UTF-8编码的文件?

如何使用Python SimpleHTTPServer提供UTF-8编码的文件? 参考资料: https://stackoverflow.com/questions/15288891/how-can-i-serve-files-with-utf-8-encoding-using-python-simplehttpserver python2 python -c "import SimpleHTTPServer; m = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map; m[''] = 'text/plain'; m.updat…

2020-08-13 21:15 · python · 经验 · shell

在 Mac 上安全地打开应用

在 Mac 上安全地打开应用 参考资料: https://support.apple.com/zh-cn/HT202491 在 Mac 上安全地打开应用 macOS 中包含一项名为“门禁”的技术,旨在确保只有受信任的软件才能在 Mac 上运行。 获取 Mac 版应用最安全的途径是 App Store 。Apple 会审查 App Store 中的每个应用,审查通过后予以接受并添加签名,确保应用未经篡改或改动。如果某个应用存在问题,Apple 会迅速从商店中下架。 如果您从互联网或直接从开发者处下载并安装应用,macOS 仍会保护您的 Mac。当您安装来自 App Store 外部的 Mac …

2020-08-13 20:28 · 经验 · maven

eclipse中的tomcat和maven的profile协作

在使用eclipse、maven、tomcat开发java应用的时候,可能maven中使用到了maven的profile来切换不同的环境(dev 开发、test 测试、prod 线上)。 如果在eclipse中的tomcat启动该项目的时候,如何让maven的profile生效呢? 回答: 鼠标右键点击eclipse的project,找到Properties的选项,弹出窗口。在窗口的左侧找到Maven的配置,有一项配置是:Active Maven Profiles(comma separated),在这里填写你指定的maven的profile,然后启动tomcat即可。 下面是网上给出的解决…

2020-08-07 16:44 · eclipse · 经验 · tomcat · 非技术 · maven

python计算方法耗时

from datetime import datetime start = datetime.now() # your code end = datetime.now() time_taken = end - start print 'Time: ', time_taken # output: Time: 0:00:00.000019

2020-07-21 10:18 · python · 经验 · DateTime · pydatetime

eclipse Node.js Version Couldn't be Determined

Mac系统,eclipse报错: Node.js Version Couldn't be Determined 已经安装了node,依然报错。 解决办法:在eclipse的配置文件eclipse.ini里面追加一个JVM参数指定node的位置,可以解决问题,如下: -Dorg.eclipse.wildwebdeveloper.nodeJSLocation=/usr/local/bin/node node的安装位置每个机器可能不同,需要自己定位一下。 参考资料: https://github.com/eclipse/wildwebdeveloper/issues/298

2020-07-21 09:53 · eclipse · 经验 · 非技术

springboot的json的时间格式:时间戳

springboot项目中javabean的字段是Date类型,需要通过Controller提供的HTTP API 返给客户端时间戳的形式。 可以指定配置如下: spring.jackson.serialization.write-dates-as-timestamps: true 这样Date类型的字段都会被序列化为时间戳timestamp的格式: "createTime": 1592897548000 参考资料: https://stackoverflow.com/questions/27516499/json-date-format-in-spring-boot

2020-07-07 17:52 · java · Spring · springboot