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
In ES5:
function pluck(array, key) {
return array.map(function(obj) {
return obj[key];
});
}
In ES6:
function pluck(array, key) {
const remove = (arr, func) =>
Array.isArray(arr) ? arr.filter(func).reduce((acc, val) => {
arr.splice(arr.indexOf(val), 1); return acc.concat(val);
}, [])
: [];
// remove([1, 2, 3, 4], n => n % 2 == 0) -> [2, 4]
@leafiy
leafiy / truncateString.js
Created May 18, 2018 18:56
截取字符串
const truncateString = (str, num) =>
str.length > num ? str.slice(0, num > 3 ? num - 3 : num) + '...' : str;
// truncateString('boomerang', 7) -> 'boom...
function mix(...mixins){
class Mix{};
for (let mixin of mixins){
copyProperties(Mix,mixin);
copyProperties(Mix.prototype,mixin.prototype);
}
}
function copyProperties(target,source){
for (let key of Reflect.ownKeys(source)){
if(key !== 'constructor' && key !== 'prototype' && key !== 'name'){
@leafiy
leafiy / 能否整除.js
Created May 18, 2018 18:55
isDivisible
const isDivisible = (dividend, divisor) => dividend % divisor === 0;
// isDivisible(6,3) -> true
function getQuerySrings() {
var qs = location.search.length > 0 ? location.search.substring(1) : "";
var args = {};
var items = qs.length ? qs.split('&') : [];
var item = null,
name = null,
value = null,
i = 0;
for (var i = 0; i < items.length; i++) {
item = items[i].split('=');
background-image: url('data:image/gif;base64,R0lGODlhPAA8APYAAJeXl56enp+fn6CgoKGhoaKioqOjo6SkpKWlpaampqenp6ioqKmpqaqqqqurq6ysrK2tra6urq+vr7CwsLGxsbKysrOzs7S0tLW1tba2tre3t7i4uLm5ubq6uru7u7y8vL29vb6+vr+/v8DAwMHBwcLCwsPDw8TExMXFxcbGxsfHx8jIyMnJycrKysvLy8zMzM3Nzc7Ozs/Pz9DQ0NHR0dLS0tPT09TU1NXV1dbW1tfX19nZ2dra2tvb29zc3N3d3eDg4OHh4ePj4wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkEAEIAIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAPAA8AAAH/oBCgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpuKJgwMJ5ycBQAABaKbBKUEqI9BQUCIA6UDhyELDRytg7BAQYezALWGCgEBDLuCvUCxhcHDhA4CAgELyULLzYTPhSAF0wMS10LMzL/btIUNAdPW49nngtyDFQPTBBjjyuXaQqoArAYlmCYggr5B/OIZKGVgUAR7Ak5x+tGjh49Dy+JdMGDgwiAG7Aoe8iBBwgdJPXio7PHDUK94hx5MU2CIQ4QEBw5MQKmyZw9DzBghOGDIggIESA+I49lT5cVLFhYgndpABCUfTVdagpBg6oEFFDClbPpzkoOpCBJMIKHJx1ge/mUlPRiK4IEGVG6fUpowocPBv4ADCz7EIweOw4gR88BUIoOFx5AfY0j
function excerpt(str, nwords) {
var words = str.split(' ');
words.splice(nwords, words.length-1);
return words.join(' ') +
(words.length !== str.split(' ').length ? '&hellip;' : '');
}
originUrl.replace(/(\.[\w\d_-]+)$/i, size+'$1');
server {
root /webserver;
location ~* \.(eot|otf|ttf|woff|svg)$ {
add_header Access-Control-Allow-Origin *;
}
}
server {
root /webserver;