Skip to content

Instantly share code, notes, and snippets.

View leafiy's full-sized avatar
🐖
Working from home

leafiy

🐖
Working from home
View GitHub Profile
@leafiy
leafiy / ngx-lua.sh
Created August 9, 2017 08:30 — forked from hit9/ngx-lua.sh
Script to compile nginx on ubuntu with lua support.
#!/bin/sh
# Script to compile nginx on ubuntu with lua support.
NGX_VERSION='1.6.2'
LUAJIT_VERSION='2.0.3'
LUAJIT_MAJOR_VERSION='2.0'
NGX_DEVEL_KIT_VERSION='0.2.19'
LUA_NGINX_MODULE_VERSION='0.9.15'
@leafiy
leafiy / arraySortByCharacters
Created April 26, 2018 18:34
按字母顺序对字符串中的字符进行排序 #array #sort
const sortCharactersInString = str =>
str.split('').sort((a, b) => a.localeCompare(b)).join('');
sortCharactersInString('cabbage') -> 'aabbceg'
@leafiy
leafiy / arrayCharactersCount.js
Last active April 26, 2018 18:37
计算数组中值的出现次数 #array
const countOccurrences = (arr, value) => arr.reduce((a, v) => v === value ? a + 1 : a + 0, 0);
countOccurrences([1,1,2,1,2,3], 1) -> 3
//使用Array.reduce()在每次遇到数组中的特定值时递增计数器
var arr = 'abcdaabc';
var info = arr.split('').reduce((p, k) => (p[k]++ || (p[k] = 1), p), {});
console.log(info);
//{ a: 3, b: 2, c: 2, d: 1 }
@leafiy
leafiy / getType.js
Created April 26, 2018 18:44
严谨获取type
const getType = v => === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
getType(new Set([1,2,3])) // "set"
@leafiy
leafiy / trim.js
Created April 26, 2018 18:47
simple trim #regex #string
String.prototype.trim = function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
// or
// \/^s*|s*$\/g
@leafiy
leafiy / sort Characters In String.js
Created May 18, 2018 18:45
按字母顺序对字符串中的字符进行排序。
const sortCharactersInString = str =>
str.split('').sort((a, b) => a.localeCompare(b)).join('');
// sortCharactersInString('cabbage') -> 'aabbceg'
var arr = 'abcdaabc';
var info = arr
.split('')
.reduce((p, k) => (p[k]++ || (p[k] = 1), p), {});
console.log(info); //{ a: 3, b: 2, c: 2, d: 1 }
if( Object.prototype.toString.call( someObject ) === '[object Object]' ) {
// do your iteration
}
/^s*|s*$/g