Skip to content

Instantly share code, notes, and snippets.

diaolizhi

Block or report user

Report or block diaolizhi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@diaolizhi
diaolizhi / IpUtils.java
Last active Jul 16, 2019
获取请求的 ip 地址
View IpUtils.java
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.servlet.http.HttpServletRequest;
public class IpUtils {
public static String getIpAddr(HttpServletRequest request) {
String ipAddress = null;
try {
ipAddress = request.getHeader("x-forwarded-for");
@diaolizhi
diaolizhi / a.js
Created Apr 28, 2019
JavaScript 格式化后端返回的时间
View a.js
new Date(data.updated).toLocaleString();
View a.java
public static String decrypt(String encrypted) {
String KEY = ")O[NB]6,YF}+efcaj{+oESb9d8>Z'e9M";
String IV = "L+\\~f4,Ir)b$=pkf";
try {
IvParameterSpec iv = new IvParameterSpec(IV.getBytes("UTF-8"));
SecretKeySpec skeySpec = new SecretKeySpec(KEY.getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
@diaolizhi
diaolizhi / a.java
Last active Apr 10, 2019
Map 遍历时删除元素
View a.java
// 创建 Map
Map<String, String> map = new HashMap<>();
// 添加元素
map.put("1", "张三");
map.put("2", "李四");
map.put("3", "王五");
// 获取存放键值的集合
// Map 并没有 iterator 方法,所以不能 map.iterator() 获取迭代器
@diaolizhi
diaolizhi / ReloadSystem.java
Created Jan 13, 2019
Java 执行 shell 脚本
View ReloadSystem.java
public class ReloadSystem {
public static void reloadSystem() {
ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command("bash", "-c", "bash ~/tieba-demo/Tieba/reload.sh");
try {
Process process = processBuilder.start();
@diaolizhi
diaolizhi / reload.sh
Last active Jan 13, 2019
Linux git 同步 maven 编译 java -jar 执行
View reload.sh
# 项目名
PRONAME="demo"
#echo $PRONAME
# 项目所在路径
PROPATH='/root/tieba-demo/Tieba/'
nohup git pull origin master >/dev/null 2>&1
#git pull origin master
cd $PROPATH
@diaolizhi
diaolizhi / insert.java
Last active Jan 7, 2019
mysql 插入数据时如果存在主键则只更新
View insert.java
@Insert("INSERT INTO t_email_link VALUES (#{email}, #{link}, DATE_ADD(CURDATE(), INTERVAL 2 DAY))" +
"ON DUPLICATE KEY UPDATE link=#{link}, exp=DATE_ADD(CURDATE(), INTERVAL 2 DAY)")
void saveEmailAndChangePasswordLink(@Param("email") String email, @Param("link") String link);
//重点是 ON DUPLICATE KEY UPDATE
@diaolizhi
diaolizhi / insert.java
Created Jan 7, 2019
mysql 插入数据时如果存在主键则跳过
View insert.java
@Insert("INSERT IGNORE INTO t_user " +
"(email, password, salt, is_active) " +
"VALUES (#{email}, #{password}, #{salt}, 1)")
int addUser(TUser user);
//重点是 IGNORE
View RandomString.java
import java.security.SecureRandom;
import java.util.Locale;
import java.util.Objects;
import java.util.Random;
public class RandomString {
/**
* Generate a random string.
*/
View Bootstrap 点击时自动隐藏导航栏
<nav class="navbar navbar-light navbar-expand-md navigation-clean-button">
<div data-toggle="collapse" data-target=".navbar-collapse.show" class="container"><router-link class="navbar-brand" to="/">首页</router-link><button class="navbar-toggler" data-toggle="collapse" data-target="#navcol-1"><span class="sr-only">Toggle navigation</span><span class="navbar-toggler-icon"></span></button>
<div class="collapse navbar-collapse"
id="navcol-1">
<ul class="nav navbar-nav mr-auto">
<li class="nav-item" role="presentation"><router-link class="nav-link" to="/see-other-forum-list">查贴吧</router-link></li>
<li class="nav-item" role="presentation"><a class="nav-link" href="#">Second Item</a></li>
<li class="dropdown"><a class="dropdown-toggle nav-link dropdown-toggle" data-toggle="dropdown" aria-expanded="false" href="#">Dropdown</a>
<div class="dropdown-menu" role="menu"><a class="dropdown-item" role="presentation" href=
You can’t perform that action at this time.