Skip to content

Instantly share code, notes, and snippets.

@jecyhw
jecyhw / TracingScript.java
Last active March 3, 2019 09:52
btrace示例
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
@BTrace
public class TracingScript {
@OnMethod(
clazz="java.net.Socket",
method="setImpl",
location=@Location(Kind.RETURN)
@jecyhw
jecyhw / start-hadoop-all.sh
Created November 27, 2017 01:44
start-dfs.sh start-yarn.sh mr-jobhistory-daemon.sh start historyserver
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@jecyhw
jecyhw / stop-hadoop-all.sh
Last active November 27, 2017 01:45
stop-dfs.shstop-yarn.shmr-jobhistory-daemon.sh stop historyserver
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@jecyhw
jecyhw / PoiExcelExample.java
Last active May 16, 2017 07:24
poi创建excel示例
public void exportProj(HttpServletResponse response) {
HSSFWorkbook workbook = new HSSFWorkbook();
final List<String> headers = new ArrayList<>();
headers.add("列1");
headers.add("列2");
headers.add("列3");
headers.add("列4");
Map<Integer, JSONArray> map;
for (Integer cityId : map.keySet()) {
@jecyhw
jecyhw / JFreeChartExample.java
Last active May 13, 2017 07:07
JFreeChart时间序列图绘制
//关于乱码解决,将相应的字体文件拷贝到$JAVA_HOME/jre/lib/fonts/fallback文件夹下即可
static private Font font = new Font("宋体", Font.PLAIN, 12);
public byte[] jFreeChartExample(String day) {
try {
Date end = DateUtils.parseDate(day, TableHelper.YYYY_MM_DD);
Date start = DateUtils.addDays(end, -29);
TimeSeriesCollection collTransfer = new TimeSeriesCollection();
TimeSeriesCollection collWaitTime = new TimeSeriesCollection();
TimeSeries seriesTransfer = new TimeSeries("平均转接次数");
@jecyhw
jecyhw / XlsxCopySheet.java
Last active January 13, 2017 14:20
java jxl excel copy a sheet
private void copyExcelSheet(Sheet sourceSheet, WritableSheet destSheet) {
for (int i = 0; i < sourceSheet.getRows(); ++i) {
for (int j = 0; j < sourceSheet.getColumns(); ++j) {
Cell cell = sourceSheet.getCell(j, i);
Label label = new Label(j, i, cell.getContents().trim());
CellFormat readFormat = cell.getCellFormat();
if (readFormat != null) {
label.setCellFormat( new WritableCellFormat(readFormat));
}
try {
@jecyhw
jecyhw / git-ignore.sh
Created January 10, 2017 13:42
.gitignore doesn't work solved
git rm --cached -r .
git add .
@jecyhw
jecyhw / RestTemplateWithHandleRedirect.java
Created January 3, 2017 00:44
followredirect in resttemplate when http status 302
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
HttpClient httpClient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
factory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(factory);
var pluploadOptions = {
runtimes : 'html5,flash,silverlight,html4',
flash_swf_url : addBasePath('plugin/plupload/Moxie.swf'),
silverlight_xap_url : addBasePath('plugin/plupload/Moxie.xap'),
multi_selection: false,
file_data_name: 'file',
multipart_params : {
_csrf: token
},
filters : {
@jecyhw
jecyhw / AjaxAwareAuthenticationEntryPoint.java
Last active February 10, 2022 05:59
spring boot ajax session timeout
public class AjaxAwareAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint {
public AjaxAwareAuthenticationEntryPoint(String loginFormUrl) {
super(loginFormUrl);
}
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
String ajaxHeader = ((HttpServletRequest) request).getHeader("X-Requested-With");
if ("XMLHttpRequest".equals(ajaxHeader)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Ajax Request Denied (Session Expired)");