Skip to content

Instantly share code, notes, and snippets.

View mobynote's full-sized avatar
🎯
Focusing

Moby mobynote

🎯
Focusing
View GitHub Profile
@mobynote
mobynote / AppService.java
Created October 10, 2018 01:14
Specification Example
public List<AppResponseVO> findLatestAndSubmittedAppsByAppId() {
return appRequestRepository.findAll(this::buildSpecification).stream()
.map(AppResponseVO::new)
.sorted(Comparator.comparing((AppResponseVO appResponse) -> {
switch (AppLifeCycleStatus.valueOf(appResponse.getStatus())) {
case IN_REVIEW:
return 1;
case ONLINE:
return 2;
case REJECTED:
@mobynote
mobynote / MonitorListenerTest.java
Created April 17, 2018 08:49
UT Example - mockito fake, list.sort
package com.mobynote.listener;
import com.mobynote.dto.HealthValue;
import com.mobynote.entity.DeviceErrorLog;
import com.mobynote.listener.event.DeviceErrorLogEvent;
import com.mobynote.repository.DeviceErrorLogRepository;
import com.mobynote.util.CommonUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.Test;
@mobynote
mobynote / EncryptorTest.java
Created March 30, 2018 06:07
Test RSA encryption and decryption
package com.moby.security;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.time.StopWatch;
import org.junit.Test;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import java.security.*;
@mobynote
mobynote / rsa_test.java
Created March 19, 2018 03:24
Use RSA to encrypt and decrypt in Java
@Test
public void encrypt_decrypt_jdk_rsa() throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, NoSuchPaddingException, BadPaddingException, IllegalBlockSizeException {
String source = "Hala Madrid!";
// 1. init secureKey
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(512);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
RSAPublicKey rsaPublicKey = (RSAPublicKey) keyPair.getPublic();
RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();
@mobynote
mobynote / SecureProviderTest.java
Last active March 12, 2018 06:23
Java use AES128
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
import java.security.SecureRandom;
import java.security.Security;
@mobynote
mobynote / DemoRepository
Created March 7, 2018 03:17
Use jdbcTemplate implement a pagination in spring
package com.domain;
import com.domain.Module;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
@mobynote
mobynote / JQuery 控制全选复选框
Last active July 25, 2016 07:16
JQuery v1.11.3中attr()设置checkbox选中状态无效,应该使用prop()替换attr()
<input type="checkbox" id="cbtn_all"> 全选/取消全选
<input type="checkbox" name="cbtn_id">A
<input type="checkbox" name="cbtn_id">B
<input type="checkbox" name="cbtn_id">C
// 全选按钮,控制其它复选框
$(function (){
$('#cbtn_all').click(function(){
if(this.checked){
$(':checkbox[name="cbtn_id"]').prop("checked", true);