Skip to content

Instantly share code, notes, and snippets.

@aNd1coder
aNd1coder / php2json.js
Created October 19, 2016 03:32
Convert php object to json in nodejs
function PHP2JSON(phpFilePath) {
return new Promise(function(resolve, reject) {
childProcess.exec(
'php -r \'include("' + phpFilePath + '"); print json_encode($php_object);\'',
function(err, stdout, stderr) {
if (err) {
console.log(err)
return
}
resolve(JSON.parse(stdout))
@aNd1coder
aNd1coder / libuv-errorno-list.txt
Created October 18, 2016 02:40
libuv errorno list
# https://github.com/joyent/libuv/blob/master/include/uv.h#L114
E2BIG - "argumentlisttoolong"
EACCES - "permissiondenied"
EADDRINUSE - "addressalreadyinuse"
EADDRNOTAVAIL - "addressnotavailable"
EAFNOSUPPORT - "addressfamilynotsupported"
EAGAIN - "resourcetemporarilyunavailable"
EAI_ADDRFAMILY - "addressfamilynotsupported"
EAI_AGAIN - "temporaryfailure"
EAI_BADFLAGS - "badai_flagsvalue"
@aNd1coder
aNd1coder / default.conf
Created September 13, 2016 08:19
NGiNX Configuration for Vue-Router in HTML5 Mode
server {
listen 80 default_server;
listen [::]:80 default_server;
root /your/root/path;
index index.html;
server_name you.server.com;
@aNd1coder
aNd1coder / connection-remote-mongodb.bat
Created September 12, 2016 09:56
远程连接mongodb时,27017端口连接不上的解决办法
# 开放 27017 端口访问
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 27017 -j ACCEPT
# 修改 mongod.conf 端口绑定
bindIp: 0.0.0.0
@aNd1coder
aNd1coder / jsonformat.js
Last active October 18, 2016 02:27
Json object format for highlight.js and append field comment
import _ from 'lodash'
export function jsonformat(body) {
let htmlBlock = ''
let space = ' '
let index = 0
let last = false
let toString = Object.prototype.toString
let self = this
@aNd1coder
aNd1coder / Object Flatten
Last active September 7, 2016 03:28 — forked from penguinboy/Object Flatten
Flatten javascript objects into a single-depth object
var flattenObject = function(ob) {
var toReturn = {};
for (var i in ob) {
if (!ob.hasOwnProperty(i)) continue;
if ((typeof ob[i]) == 'object') {
var flatObject = flattenObject(ob[i]);
toReturn[i] = ob[i];
@aNd1coder
aNd1coder / mongodb.sql
Last active September 18, 2016 02:40
MongoDB 常用工具
/* 新增字段 */
db.getCollection('collection_name').update({},{$set:{'field_name':'xxx'}},false,true)
/* 删除字段 */
db.getCollection('collection_name').update({},{$unset:{'field_name':''}},{multi:true})
@aNd1coder
aNd1coder / text-autospace.js
Created August 18, 2016 12:02
为什么我就是能这样娴熟地加上空格呢?
// https://zizhengwu.github.io/daft-auto-spacing/
var unicode = [];
unicode['latin'] = ['[A-Za-z0-9\u00C0-\u00FF\u0100-\u017F\u0180-\u024F\u1E00-\u1EFF]'];
unicode['punc'] = ['[@&=_\,\.\?\!\$\%\^\*\-\+\/]', '[\(\\[\'"<‘“]', '[\)\\]\'">”’]'];
unicode['hanzi'] = ['[\u4E00-\u9FFF]', '[\u3400-\u4DB5\u9FA6-\u9FBB\uFA70-\uFAD9\u9FBC-\u9FC3\u3007\u3040-\u309E\u30A1-\u30FA\u30FD\u30FE\uFA0E-\uFA0F\uFA11\uFA13-\uFA14\uFA1F\uFA21\uFA23-\uFA24\uFA27-\uFA29]', '[\uD840-\uD868][\uDC00-\uDFFF]|\uD869[\uDC00-\uDEDF]', '\uD86D[\uDC00-\uDF3F]|[\uD86A-\uD86C][\uDC00-\uDFFF]|\uD869[\uDF00-\uDFFF]', '\uD86D[\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1F]', '[\u31C0-\u31E3]'];
unicode['biaodian'] = ['[·・︰、,。:;?!—ー⋯….·/]', '[「『(〔【《〈“‘]', '[」』)〕】》〉’”]'];
unicode['zhuyin'] = [];
unicode['zhuyin'][0] = '[\u3105-\u312D\u31A0-\u31BA]';
unicode['zhuyin']['shengmu'] = '[\u3105-\u3119\u312A-\u312C\u31A0-\u31A3]';
@aNd1coder
aNd1coder / updatedb.sh
Created July 3, 2016 04:35
Update the locate DB on OS X
sudo /usr/libexec/locate.updatedb
@aNd1coder
aNd1coder / ios-aspect-ratio.css
Created June 18, 2016 17:02
iOS aspect ratio
/*================iPhone < 5==================*/
@media screen and (device-aspect-ratio: 2/3) {}
/*================iPhone 5==================*/
@media screen and (device-aspect-ratio: 40/71) {}
/*================iPhone 6==================*/
@media screen and (device-aspect-ratio: 375/667) {}
/*================iPhone 6+==================*/