Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

大杂烩 #24

Open
itboos opened this issue Jul 28, 2018 · 12 comments
Open

大杂烩 #24

itboos opened this issue Jul 28, 2018 · 12 comments

Comments

@itboos
Copy link
Owner

itboos commented Jul 28, 2018

记录一些生活中遇到的问题和解决方案,或者一些有用的积累:

  1. 访问网站容易被劫持,有些网站无法访问
    原因: 网络供应商劫持了DNS, 注入了广告
    解决办法:
  2. 设置路由器的公共DNS, 不使用运营商提供的
  3. 独立设置电脑,手机 的DNS (路由器和设备都设置了话,貌似是使用设备设置的)
    知乎:公共DNS哪家强?
    国内部分网络运营商需要配置DNS
    Mac :修改 DNS 及清除 DNS 缓存
    路由器设置DNS
    114官网
@itboos
Copy link
Owner Author

itboos commented Oct 9, 2018

@itboos
Copy link
Owner Author

itboos commented Oct 10, 2018

.git 里面的配置:
  [core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = ssh://git@git.internal.******.com.cn:10022/supermonkey-web/monkey-official-website.git
	fetch = +refs/heads/*:refs/remotes/origin/*
	pushurl = ssh://git@git.internal.******..com.cn:10022/supermonkey-web/monkey-official-website.git
[branch "master"]
	remote = origin
	merge = refs/heads/master

@itboos
Copy link
Owner Author

itboos commented Oct 15, 2018

几个样式导致 Safari (ios 自动重启):
放上千个div, 里面的样式就会导致iOS 出现bug, 但是安卓上不会, 貌似是因为安卓上不支持此属性

   div {
          backdrop-filter: blur(10px); 
         -webkit-backdrop-filter: blur(10px);
          width:10000px; height:10000px;
       }

@itboos
Copy link
Owner Author

itboos commented Feb 11, 2019

浅拷贝和深拷贝

    // 浅拷贝
var obj2 = { a: 1, b : {c: 3} }
var newObj = Object.assign({}, obj2)

console.log(newObj.b === obj2.b) // true
// 其中,obj2和newObj 的b属性是引用的同一个对象,即 b 属性的引用是一样的

// 深拷贝 使用JSON.stringify, 
// 缺点: 对象的属性如果是方法的话, 则这个属性会被忽略(即这个属性不能被string化)
// Deep Clone
let obj1 = { a: 0 , b: { c: 0}, d: function() {}};
let obj3 = JSON.parse(JSON.stringify(obj1));
obj1.a = 4;
obj1.b.c = 4;
console.log(JSON.stringify(obj3)); // { a: 0, b: { c: 0}}
console.log(obj1.b === obj3.b) // false

@itboos
Copy link
Owner Author

itboos commented Feb 13, 2019

判断是否是原生js对象

 from redux
 /**
 * @param {any} obj The object to inspect.
 * @returns {boolean} True if the argument appears to be a plain object.
 */

function isPlainObject(obj) {
  if (typeof obj !== 'object' || obj === null) return false;
  var proto = obj;

  while (Object.getPrototypeOf(proto) !== null) {
    proto = Object.getPrototypeOf(proto);
  }

  return Object.getPrototypeOf(obj) === proto;
}
// 如果只是简单的判断是否是对象的话,可以使用;
Object.prototype.toString.call(obj) === ''[object Object]''

// 举个🌰:
var o1 = {};
function person(a, b) {
  this.a = a
  this.b = b
}

var o2 = new person(1,2);
var res = isPlainObject(o1)
var res2 = isPlainObject(o2)
console.log('res:', res) // false
console.log('res:', res2) // flase

// 从代码的定义可以看出,是否是原生对象,即判断这个对象最上层原型是不是就是 
// Object.getPrototypeOf(obj) 拿到的原型

@itboos
Copy link
Owner Author

itboos commented Apr 8, 2019

new Date 参数兼容性更好的写法

http://dygraphs.com/date-formats.html
https://github.com/iamkun/dayjs/blob/dev/src/constant.js
ECMA关于new Date的参数说明

 // new Date('2019-04-06 17:00:00' )  这种写法在iOS 系统上存在兼容性问
 // 将 '2019-04-06 17:00:00'   使用者种有兼容性更好的写法,使用正则捕获,分别取出年月日,时分秒
// new Date(2019, 04, 06, 17, 0,0,0)

 const REGEX_PARSE = /^(\d{4})-?(\d{1,2})-?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?.?(\d{1,3})? $/
 const d = dateStr.match(REGEX_PARSE);
 const data = new Date(d[1], d[2] - 1, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, d[7] || 0)

// 取出来的值时字符串,但是转换过程中,会把年月日,时分秒转换成Number 类型

@itboos
Copy link
Owner Author

itboos commented Apr 8, 2019

RFC822 or ISO 8601 date

rfc2822 草案
ECMA262规范

@itboos
Copy link
Owner Author

itboos commented Apr 8, 2019

日期处理相关

https://github.com/you-dont-need/You-Dont-Need-Momentjs#quick-links
https://github.com/iamkun/dayjs
moment.js

获取 UTC 时间戳

new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000;

how-do-i-get-a-utc-timestamp-in-javascript

@itboos
Copy link
Owner Author

itboos commented Aug 22, 2019

new Function 笔记

原文链接-new_-function

  • new Function 通常情况下不建议使用,但是有一些特殊场景需要用到
  • new Function 的语法
  let func = new Function ([arg1, arg2, ...argN], functionBody);

可以有下面三种等价的写法

new Function('a', 'b', 'return a + b'); // basic syntax
new Function('a,b', 'return a + b'); // comma-separated
new Function('a , b', 'return a + b'); // comma-separated with spaces
  • new Function 的特性
  • 当一个 函数以 new Function 的形式申明时, new Function 里面的作用域并不指向单前的
    词法作用域,而是指向全局的词法作用域(即原来的闭包环境丢失了,new Function 里的环境是全局的)
 function getFunc() {
  let value = "test";
  console.log('this", this) // => 返回全局变量,在浏览器里,this 就是window
  let func = new Function('alert(value)');
  
  return func;
}

getFunc()(); // error: value is not defined

@itboos
Copy link
Owner Author

itboos commented Aug 25, 2019

@itboos
Copy link
Owner Author

itboos commented Nov 5, 2019

js 生成 GUIID

create-guid-uuid-in-javascript

@itboos
Copy link
Owner Author

itboos commented Nov 12, 2019

一键开启 macOS HiDPI

让 mac 显示器 分辨率更佳的设置

1、接好显示器
2、运行这个脚本 ./patch-edid.rb
3、重启电脑按住CMD+R进入恢复模式,在终端里输入csrutil disable回车关闭SIP
4、把脚本生成的文件夹(类似:DisplayVendorID-5e3)覆盖到:/System/Library/Displays/Contents/Resources/Overrides
5、重新连接显示器

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant