Skip to content

Instantly share code, notes, and snippets.

View xie-qianyue's full-sized avatar

XIE Qianyue xie-qianyue

  • NetEase
  • Hangzhou
View GitHub Profile
@xie-qianyue
xie-qianyue / dateUtilities.js
Last active March 2, 2016 14:20
JS Utilities
// Transform the date format to String format
var Date = new Date();
var str_GMT = date.toGMTString(); // 把Date对象的日期(一个数值)转变成一个GMT时间字符串,返回类似下面的值:Weds,14 May 2007 10:02:02 GMT(精确的格式依赖于计算机上所运行的操作系统而变)
var str_Locale = date.toLocaleString(); // 把Date对象的日期(一个数值)转变成一个字符串,使用所在计算机上配置使用的特定日期格式 UTC() 使用Date UTC(年、月、日、时、分、秒),以自从1997年1月1日00:00:00(其中时、分、秒是可选的)以来的毫秒数的形式返回日期
// Get the interval of two days
alert("间隔天数为:"+(new Date('2005/8/15')-new Date('2003/9/18'))/1000/60/60/24+"天");
// Get the detail interval of two days
var d1=new Date("2004/09/16 20:08:00");
@xie-qianyue
xie-qianyue / FTPDownloadFile.java
Last active October 15, 2021 22:23
Java FTP/SFTP Client
public class DownloadFileService {
private static final Logger logger = LogManager.getLogger(DownloadFileService.class);
public static boolean download(final String[] lesFichiers, final String inputFolder, final String outputFolder,
final String suffix, final String server, final int port, final String user, final String pass) {
boolean success = false;
OutputStream outputStream;
final FTPClient ftpClient = new FTPClient();
@xie-qianyue
xie-qianyue / dateValidationDirective.js
Last active March 2, 2016 14:08
Angular Directive
hdrDirectives.directive('hdrMaxOneWeekAfter', ['dateServices', function (dateServices) {
'use strict';
return {
require: 'ngModel',
restrict: 'A',
link: function (scope, elm, attrs, ctrl) {
var valider = function (viewValue) {
// pour ça marche, le ngModel correspondant doit etre 'formaData.**'
var greaterDate = scope.formData[attrs.hdrMaxOneWeekAfter],
greaterDateCtrl = angular.element(document.querySelector('[name=' + attrs.hdrMaxOneWeekAfter + ']')).controller('ngModel');
@xie-qianyue
xie-qianyue / simplePopup.js
Created March 2, 2016 14:06
jQuery snippets
/* Au chargement de la page */
$(document).ready(function() {
$("#legend").mouseover(function(event) {
createTooltip(event);
}).mouseout(function(){
hideTooltip();
});
});
function createTooltip(event){
@xie-qianyue
xie-qianyue / containerComponentExample.js
Created March 30, 2016 12:24
React container component
class TodoContainer extends Component {
componentDidMount() {
this.setState({ isLoding: true });
fetch('/todos.json').then(
todos => {
this.setState({
error: null,
todos,
isLoding: false
});
@xie-qianyue
xie-qianyue / decoratorFunctionExample.js
Created March 30, 2016 12:25
React decorator function
function BaseTodoItem(props) {
return {
render() {
return (
<label>{props.content}</label>
)
}
}
}
function flatten(arr) {
return [].concat.apply([], arr);
}
function flattenES6(arr) {
return [].concat(...arr);
}
@xie-qianyue
xie-qianyue / arrowThis.js
Last active April 8, 2016 14:42
Binding this in callback
function Person(){
this.age = 0;
setInterval(() => {
this.age++; // |this| properly refers to the person object
console.log(this.age); // 1 2 3 ...
}, 1000);
}
var p = new Person();
function foo() {
var f = (...args) => args[0];
return f(2);
}
console.log(foo()); // 2
@xie-qianyue
xie-qianyue / GenericBeanDefinitionExample.java
Created June 11, 2018 09:25
Spring - Register Bean by GenericBeanDefinition
public class GenericBeanDefinitionExample {
public static void main (String[] args) {
DefaultListableBeanFactory context =
new DefaultListableBeanFactory();
GenericBeanDefinition gbd = new GenericBeanDefinition();
gbd.setBeanClass(MyBean.class);
MutablePropertyValues mpv = new MutablePropertyValues();