Skip to content

Instantly share code, notes, and snippets.

View greenyleaf's full-sized avatar

Z greenyleaf

  • China
View GitHub Profile
@greenyleaf
greenyleaf / QqwryParser.java
Created July 5, 2022 00:18
a Geo IP library parser of qqwry, cz88
@Component
@Slf4j
public class QqwryParser {
@Value("qqwry.dat")
private ClassPathResource resource;
public String[] versionInfo() throws IOException {
try (RandomAccessFile file = new RandomAccessFile(resource.getFile(), "r")) {
file.seek(4);
int lastIndexRecordOffset = Integer.reverseBytes(file.readInt());
@greenyleaf
greenyleaf / my-coupons.ftlh
Last active June 19, 2020 13:48
a mobile page Freemarker template of coupons list, used a little CSS3.
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1,viewport-fit=cover">
<meta name="format-detection" content="telephone=no">
<meta name="applicable-device" content="mobile">
<meta name="screen-orientation" content="portrait">
<title>我的优惠券</title>
@greenyleaf
greenyleaf / WxAuthInterceptor.java
Created June 19, 2020 13:30
a Spring interceptor for Weixin(wechat) oauth2
package top.sdrkyj.custom.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.springframework.web.util.UriComponentsBuilder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@greenyleaf
greenyleaf / WxService.java
Created June 19, 2020 13:27
a Spring service for Weixin(wechat) oauth2
package top.sdrkyj.custom.service;
import com.alibaba.fastjson.JSON;
import top.sdrkyj.custom.dao.weixin.WxUserInfoDao;
import top.sdrkyj.custom.entity.weixin.WxAccessToken;
import top.sdrkyj.custom.entity.weixin.WxUserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@greenyleaf
greenyleaf / WxController.java
Last active June 19, 2020 13:27
a Spring controller for Weixin(wechat) page authorization, enhanced security.
package top.sdrkyj.custom.controller;
import top.sdrkyj.custom.config.WxAuthInterceptor;
import top.sdrkyj.custom.dto.RestMsg;
import top.sdrkyj.custom.entity.weixin.WxUserInfo;
import top.sdrkyj.custom.service.WxService;
import org.apache.commons.codec.binary.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@greenyleaf
greenyleaf / InvoiceDao.java
Last active June 19, 2020 12:30
a MyBatis DAO interface, CRUD
package top.sdrkyj.custom.dao;
import top.sdrkyj.custom.entity.Invoice;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
@greenyleaf
greenyleaf / CkMsg.java
Last active June 19, 2020 12:53
Response entity class for returning messages after uploading files from CKEditor 4.
package top.sdrkyj.custom.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
public class CkMsg {
/**
* null is permitted。 the filename for the uploaded file
*/
private String fileName;
@greenyleaf
greenyleaf / AccessInterceptor.java
Last active June 19, 2020 11:47
an interceptor in Spring MVC for logging user access, using DAO persistence and Logback logging. Process the forwarded request.
package top.sdrkyj.custom.config;
import top.sdrkyj.custom.entity.AccessLog;
import top.sdrkyj.custom.entity.Account;
import top.sdrkyj.custom.service.AccessLogService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
@greenyleaf
greenyleaf / ajax-file-upload.js
Last active March 29, 2021 12:30
Upload files using ajax. Using FormData only if there are file fields in the form, to reduce the upload size when not needed.
$.ajax('http://custom.sdrkyj.top/form-action-url', {
contentType: hasFiles ? false : undefined,
data: hasFiles ? new FormData(formDom) : $(formDom).serialize(),
method: 'post',// 'patch'
dataType: 'json',
processData: !hasFiles,
xhr: function () {
let xhr = $.ajaxSettings.xhr();
hasFiles && xhr.upload.addEventListener('progress', function (e) {
if (e.lengthComputable && e.total > 1 << 17) {
@greenyleaf
greenyleaf / china-national-radio.m3u8
Last active April 9, 2021 05:18
China National Radio streams
#EXTM3U
#EXTINF:60,中国之声
#EXTVLCOPT:network-caching=1000
http://ngcdn001.cnr.cn/live/zgzs/index.m3u8
#EXTINF:60,中国之声 low resolution
#EXTVLCOPT:network-caching=1000
http://ngcdn001.cnr.cn/live/zgzs48/index.m3u8
#EXTINF:60,经济之声
#EXTVLCOPT:network-caching=1000
http://ngcdn002.cnr.cn/live/jjzs/index.m3u8