Skip to content

Instantly share code, notes, and snippets.

View ClausClaus's full-sized avatar
😁
Happy coding

ClausClaus

😁
Happy coding
View GitHub Profile
@ClausClaus
ClausClaus / parseUrl.js
Last active June 29, 2020 03:17
将链接格式化为对象
function parseUrl(url) {
var a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':',''),
host: a.hostname,
port: a.port,
query: a.search,
params: (function(){
@ClausClaus
ClausClaus / important.md
Last active April 5, 2020 14:34 — forked from stettix/things-i-believe.md
Things I believe

Important

  • 系统设计

    • 更好的系统通常是更小,更简单的系统
    • 要设计健康的系统,请分而治之。将问题分成较小的部分
    • 分而治之的工作是递归的:将系统分为更简单的子系统和组件的层次结构
    • 告诉您的应用过去的工作尤为重要,因此请确保其可审核
  • 技术

    • 当心炒作或时髦的技术,随着时间的流逝,计算机科学和工程学的基础不会发生太大变化
const array = [1,23,124,23,4,1.423,4,123,222,111,22,23];
[...new Set(array)]
array.filter((item,index)=>array.indexOf(item) === index)
array.reduce((unique,item) => unique.includes(item) ? unique: [...unique,item],[])
@ClausClaus
ClausClaus / regPhoneNum.js
Created April 4, 2020 09:39
格式化手机号码,以横杆分割
'11111111111'.replace(/^(...)(....)/g,'$1-$2-');
@ClausClaus
ClausClaus / publish.sh
Last active August 22, 2019 10:22
一键发布npm包的脚本
#!/usr/bin/env bash
# 1. 版本号每次自增;
# 2. 区分测试和生产 package.json.test, package.json.prod
# 3. 发布到生产前会二次确认
srcName='package.json.test'
if [[ $1 == "prod" ]]
then
srcName='package.json.prod'
read -p "Are you sure to publish to PRODUCTION? [Y/N]" -n 1 -r
echo ""
@ClausClaus
ClausClaus / assign.js
Created July 16, 2019 06:25
assign 对象合并
export const assign = Object.assign || function (target, ...args) {
target = Object(target);
for (let i = 0; i < args.length; i++) {
const source = args[i];
if (source !== null) {
for (const key in source) {
if (hasOwn(source, key)) {
target[key] = source[key];
}
}
@ClausClaus
ClausClaus / formatObj.html
Created March 15, 2019 14:21
从多个对象中取出需要的属性值,隐式的判断ID是否相等
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body></body>
<script type="text/javascript">
/* 无需显式的比较ID是否相等实现数据的对应格式化 */
var friends = { items: [{ user_id: 1 }] }
@ClausClaus
ClausClaus / index.html
Created February 1, 2019 09:14
jsonp example
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>jsonp请求测试</title>
</head>
<body>
@ClausClaus
ClausClaus / format-date.js
Created January 28, 2019 02:17
日期时间戳格式化
function formatDate(date, formatStr) {
if (/(Y+)/.test(formatStr)) {
formatStr = formatStr.replace(
RegExp.$1,
(date.getFullYear() + '').substr(4 - RegExp.$1.length)
)
// 返回年 :'2016-mm-dd', 'hh:mm'
}
// 定义通用的匹配模式
let o = {
@ClausClaus
ClausClaus / reset.css
Created January 28, 2019 01:29
css样式格式化
html,body{height:100%;}
html,body,h1,h2,h3,h4,h5,h6,div,dl,dt,dd,ul,ol,li,p,blockquote,pre,hr,figure,table,caption,th,td,form,fieldset,legend,input,button,textarea,menu{margin:0;padding:0;}
header,footer,section,article,aside,nav,hgroup,address,figure,figcaption,menu,details{display:block;}
table{border-collapse:collapse;border-spacing:0;}
caption,th{text-align:left;font-weight:normal;}
html,body,fieldset,img,iframe,abbr{border:0;}
i,cite,em,var,address,dfn{font-style:normal;}
[hidefocus],summary{outline:0;}
li{list-style:none;}
h1,h2,h3,h4,h5,h6,small{font-size:100%;}