Skip to content

Instantly share code, notes, and snippets.

@DarwinniwraD
DarwinniwraD / getUnflattenToTree.js
Last active December 3, 2019 13:47
array of objects to tree
export default const getUnflatten = (arr, idFieldName, parentFieldName) => (arr, parentid) => arr.reduce((all, item) => item[parentFieldName] === parentid ? all.concat({...item, children: getUnflatten(arr, item[idFieldName])}): all, [] )
@DarwinniwraD
DarwinniwraD / git_cheat-sheet.md
Created January 3, 2018 08:23 — forked from davfre/git_cheat-sheet.md
git commandline cheat-sheet
@DarwinniwraD
DarwinniwraD / Setting_upa_new_repo.md
Last active November 24, 2017 02:51 — forked from alexpchin/Setting_upa_new_repo.md
Create a new repository on the command line

Setting up a new Git Repo

##Create a new repository on the command line

touch README.md
git init
git add README.md
git commit -m "first commit"

git remote add origin git@github.com:/.git

@DarwinniwraD
DarwinniwraD / git_merge_local.txt
Last active May 23, 2017 06:13 — forked from vladimirtsyupko/gist:10964772
Git force pull to overwrite local files
git fetch --all
git reset --hard origin/master
git pull origin master

js复制的集中方法

众所周知,js中复制包括浅复制(Shallow Clone)和深复制(Deep Clone)两种,深复制的出现主要针对复杂数据结构,如数组和对象,其中浅复制就是运用赋值运算方式(“=”),为新对象引用所有的源对象属性,这不会产生新的对象,只是一个对象引用(reference)。而深复制则相对复杂一些,它是将所有的原始数据类型,机器所有的对象引用复制到新的对象中,这种复制最终会形成两个对象.关于两种复制的方法的论述已经有许多了,无外乎有以下三种:

  1. 第三方库,如underscore.js,jquery, loadsh

  2. JSON大法

  3. js原生方法

  4. 关于第三方库的复制方法

  1. jQuery
//This is a complete guide for centering a div with CSS.
//见过许多方法来居中div,当然有些方法因情况不同而不同
//详细可参考:
//1.Centering in CSS: A Complete Guide(https://css-tricks.com/centering-css-complete-guide/)
//2.How To Center Anything With CSS(https://codemyviews.com/blog/how-to-center-anything-with-css)
//3.CSS layout: tricks and layout techniques in ‘Learn CSS Layout’(http://book.mixu.net/css/5-tricks.html)
//4.Absolute Centering(http://codepen.io/shshaw/full/gEiDt)
/*
A (very) WIP collection of optimized/recommended jQuery plugin patterns
from @addyosmani, @cowboy, @ajpiano and others.
Disclaimer:
-----------------------
Whilst the end-goal of this gist is to provide a list of recommended patterns, this
is still very much a work-in-progress. I am not advocating the use of anything here
until we've had sufficient time to tweak and weed out what the most useful patterns