Skip to content

Instantly share code, notes, and snippets.

View codethereforam's full-sized avatar
:octocat:
Focusing

ZanyZoe codethereforam

:octocat:
Focusing
View GitHub Profile
@codethereforam
codethereforam / StreamUtil.java
Created January 13, 2019 07:57
Java 8 Distinct by property
public class StreamUtil {
private StreamUtil() {
}
/**
* stream Distinct by property
*
* @param keyExtractor keyExtractor
* @return java.util.function.Predicate<T>
* @author yanganyu
@codethereforam
codethereforam / improve-java-dev-efficiency.md
Last active January 27, 2019 06:31
一些减少代码量、提高开发效率的利器 #java
  • Spring Boot
  • mybatis-plus代码生成器和自带CRUD接口
  • lombok
  • 库: Apache Commons & guava
  • AOP
  • Java8: stream & lambda
  • 反射
  • 日志取代debug
  • IDEA:使用恰当的开发工具并熟悉、熟练使用其功能
  • 单元测试:不必运行整个项目,减少项目运行时间(好处之一)
@codethereforam
codethereforam / open-source-framework-resolve.md
Last active February 3, 2019 06:31
使用开源框架过程遇到问题解决思路

一、如何找出问题所在

  1. Google中文搜索(看一些博客)
  2. Google英文搜索(看SOF、教程等)
  3. 查看官方文档、wiki、README(中英文可能不一致,都看下)
  4. issues和PR中搜索,看看有没有其他人遇到
  5. 看项目示例(demo)和单元测试
  6. 查看、debug源码

二、如何解决

@codethereforam
codethereforam / mybatis-like.md
Created January 30, 2019 06:19
mybaits模糊查询使用<bind>标签
<select id="selectBlogsLike" resultType="Blog">
  <bind name="pattern" value="'%' + _parameter.getTitle() + '%'" />
  SELECT * FROM BLOG
  WHERE title LIKE #{pattern}
</select>

模糊查询一般有三种方式:

  1. Java代码里拼接匹配符: 代码和SQL耦合度高;查看xml不能直接看出查询条件,降低开 发效率;有可能在service层多次加%_
@codethereforam
codethereforam / java-code-generate.md
Created January 31, 2019 03:58
Java生成代码(字节码)

一、方式

  1. 代码生成器 & IDE
  2. 编译时代码生成: Pluggable Annotation Processing API
  3. 运行时代码生成: Compiler API
  4. 运行时生成字节码: cglib, javassist

二、辅助工具

  • String format tool
  • 模板引擎: freemarker, velocity
  • JavaPoet
@codethereforam
codethereforam / mysql-count.md
Last active February 1, 2019 01:48
mysql count(*) vs count(1)

perfer count(*)

  1. 官方文档:

InnoDB handles SELECT COUNT(*) and SELECT COUNT(1) operations in the same way. There is no performance difference.

  1. 阿里手册:

【强制】不要使用 count( 列名 ) 或 count( 常量 ) 来替代 count( * ) , count( * ) 是 SQL 92 定义的 标准统计行数的语法,跟数据库无关,跟 NULL 和非 NULL 无关。 说明: count( * ) 会统计值为 NULL 的行,而 count( 列名 ) 不会统计此列为 NULL 值的行。

@codethereforam
codethereforam / java-timer-task.md
Created February 2, 2019 01:58
Java项目定时任务实现方式
  • Timer
  • ScheduledExecutorService
  • spring @Scheduled
  • Quartz
  • Linux定时任务
  • 定时任务管理系统(e.g. gocron, xxl-job,功能包括监控、告警、执行日志、报表等)
@codethereforam
codethereforam / 开源的坑.txt
Last active February 18, 2019 14:35
开源的坑
我们使用开源软件大部分情况是为了不重复造轮子,使用一些别人写好的具有通用性的代码来减少我们的代码量,提高开发效率,减少开发成本。而且使用一些优秀的开源软件会比我们自己开发的好,毕竟它们被很多人使用,经受了很多人很多次的检验。
但是,有些开源软件却很坑,用它们到最后发现有不断的坑,到头来发现不如直接用底层的、未封装的API,或者自己开发。下面说些应该避免的坑:
1. 社区小(比如GitHub的star少)的开源软件
对于社区小的开源软件,当你遇到问题,很难快速解决。而那些社区大的开源软件,Google搜下很容易搜到你遇到的常见的问题。大小是相对的,那么谈谈如何比较两个开源软件的社区大小,可以比较它们在开源平台的收藏数量、issues数量、PR数量,也可以用Google trends对比下,也可以对比下Google搜索结果数目,也可以对比下它们在stackoverflow等平台搜索结果数目。
2. 国产开源软件
不是看不起国产开源软件,国产优秀的开源软件其实也有一些。但整体上看,国产开源软件文档质量不行。社区小,一般很少有外国人使用,而国外的开发者数量和质量明显高于国内。举个例子,fastjson和jackson,虽然fastjson应该比jackson性能好一点,但fastjson的功能和代码质量不如jackson,而且fastjson社区也不如jackson,当用jackson遇到问题时,用Google英文搜索下,一般很容易搜到解决办法,而用fastjson遇到问题一般只能去看看fastjson那一点点文档。顺便提一下,用中文搜索问题,一般比较难很快找到解决办法。我想原因大概如下:1、Google的中文搜索能力不如英文(baidu啥的更别谈)2、国内开发者鱼龙混杂,由于编程入门门槛低,有好多水平欠缺的开发者写了大量低质量博客,中文博客的信噪比非常糟糕,很少有我感觉还可以的博主。举个例子,CSDN博客质量简直不堪入目,我现在直接用扩展屏蔽了CSDN。
3. 不再维护的或代码贡献频率低的开源软件
在我开来,软件开发者应该要对自己的软件负责,就是一直对自己开源的软件质量负责,close所有issues,解决软件bug。做到这点很难,连我自己一些玩具开源项目都不再维护,但我会在README中标注不再维护,减少浪费有些人的时间,我也会及时close每一个issues。如果实在不想
@codethereforam
codethereforam / JsonUtil.java
Last active February 21, 2019 05:40
jackson deserialization json to generic java object
/**
* jackson deserialization json to generic java object
*
* @param jsonStr json string
* @param typeReference typeReference
* @return generic object
* @author yanganyu
* @date 2019/2/21 13:37
*/
public static <T> T parse(String jsonStr, TypeReference<T> typeReference) {
@codethereforam
codethereforam / StringUtil.java
Last active March 20, 2019 06:18
父字符串顺序匹配子字符串
/**
* String Utility
*
* @author yanganyu
* @date 2019/3/18 14:31
*/
public class StringUtil {
private StringUtil() {
}