Skip to content

Instantly share code, notes, and snippets.

@jecyhw
jecyhw / Leetcode_474_Ones_and_Zeroes.cpp
Created December 12, 2016 00:50
LeetCode Weekly Contest 12
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
struct node {
int z, o;
node() {}
@jecyhw
jecyhw / Total_Hamming_Distance.cpp
Created December 18, 2016 03:16
LeetCode Weekly Contest 13
class Solution {
public:
struct node {
int z, o;
node() {
z = o = 0;
}
};
@jecyhw
jecyhw / Concatenated_Words.java
Last active March 14, 2017 01:40
LeetCode Weekly Contest 13字典树
public class Solution {
class Node {
Node[] next = new Node[26];
boolean end = false;
void add(String s) {
Node cur = this;
for (int i = 0;i < s.length(); ++i) {
int ind = s.charAt(i) - 'a';
if (cur.next[ind] == null) {
@jecyhw
jecyhw / spring_boot_csrf.js
Last active December 22, 2016 07:05
spring boot ajax request with csrf
// <meta name="_csrf" th:content="${_csrf.token}"/>
// <meta name="_csrf_header" th:content="${_csrf.headerName}"/>
$(function () {
var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");
$(document).ajaxSend(function(e, xhr, options) {
xhr.setRequestHeader(header, token);
});
});
@jecyhw
jecyhw / plupload_picture_preview.js
Last active December 25, 2016 14:04
plupload的图片预览
//图片预览
function previewPicture(file) {
var img = new moxie.image.Image();
img.onload = function () {
$preview.attr('id', this.uid).addClass('thumbnail').html('');
this.bind('embedded', function () {
$preview.children().css({
width: '100%',
height: 'auto'
});
@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)");
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 / 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);
@jecyhw
jecyhw / git-ignore.sh
Created January 10, 2017 13:42
.gitignore doesn't work solved
git rm --cached -r .
git add .
@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 {