Skip to content

Instantly share code, notes, and snippets.

@HereChen
HereChen / npmpackageTpl.js
Created March 15, 2018 10:17
AMD, CommonJS, Browser surport for npm package
(function (global, factory) {
// 1. CommonJS: typeof exports === 'object' && typeof module !== 'undefined'
// 2. AMD: typeof define === 'function' && define.amd
// 3. Browser
// factory: function () { 'use strict'; }
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.Vue = factory());
}(this, (function () {
'use strict';
@HereChen
HereChen / trimWrapSpace.js
Created July 26, 2017 02:51
删除对象中key对应值的空格和换行符
// 剔除前后空格和换行符
function trimWrapSpace(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
// 如果是字符串, 直接去除末尾空格以及换行符.
// 注意变量中的换行符和实际换行
obj[key] = (typeof obj[key] === 'string' || obj[key] instanceof String) ? obj[key].replace(/[\\r\\n]+/g, '').replace(/^\s+|\s+$/g, '') : obj[key];
}
}
return obj;
@HereChen
HereChen / env_init.bat
Last active July 11, 2017 05:57
Window系统环境变量添加。软件单独安装到一个盘,重装系统后,直接运行bat文件添加每个软件的环境变量。
REM 系统重装环境变量初始化
REM ----------- dev ------------
REM java
set JAVA_HOME=D:\Java\jdk1.8.0_112
setx /m JAVA_HOME "%JAVA_HOME%"
REM maven
set MAVEN_HOME=D:\apache-maven-3.5.0
@HereChen
HereChen / git-ca-add
Created July 7, 2017 01:49
bower install 报错, git crt 添加
git config --system http.sslcainfo "D:\Git\mingw64\ssl\certs\ca-bundle.crt"
@HereChen
HereChen / sql-sublimt-regexp-parse.sql
Created July 6, 2017 01:14
sublime text regexp find multiline text
DROP TABLE "DB"."TABLE";
CREATE TABLE "DB"."TABLE" (
"ID" NUMBER NOT NULL ,
"TITLE" VARCHAR2(100 BYTE) NULL ,
"IMG" VARCHAR2(400 BYTE) NULL ,
"URL" VARCHAR2(400 BYTE) NULL ,
"CRETIME" DATE DEFAULT sysdate NULL ,
"NUM" NUMBER DEFAULT 0 NULL
)
LOGGING
@HereChen
HereChen / angularjs-file-upload.js
Created July 4, 2017 12:02
angularjs-file-upload
// https://stackoverflow.com/questions/16483873/angularjs-http-post-file-and-form-data
$http({
method: 'POST',
url: '/upload-file',
headers: {
'Content-Type': 'multipart/form-data'
},
data: {
email: Utils.getUserInfo().email,
token: Utils.getUserInfo().token,
// validate url
// 检查 url 是否合法
// https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
// http://regexr.com/3e6m0
function isUrl(url) {
return /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i.test(url);
}
@HereChen
HereChen / ssh-add-on-start
Last active January 31, 2018 03:31
add ssh on ubuntu start
# https://unix.stackexchange.com/questions/90853/how-can-i-run-ssh-add-automatically-without-password-prompt
$ sudo vim ~/.bashrc
if [ -z "$SSH_AUTH_SOCK" ] ; then
eval `ssh-agent -s`
ssh-add -D
ssh-add ~/.ssh/id_rsa_oschina
ssh-add ~/.ssh/id_rsa_github
ssh-add -l
fi
@HereChen
HereChen / deploy-war-local.bat
Created February 27, 2017 03:18
deploy war to local tomcat, 部署 war 包到本地 tomcat
REM local tomcat deploy
copy target\*.war %TOMCAT_HOME%\webapps\
%TOMCAT_HOME%\bin\catalina.bat start
@HereChen
HereChen / maven-war-name-custom.xml
Created February 27, 2017 02:38
maven war name custom plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/webapp</directory>
</resource>