Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

viko16 viko16

🎯
Focusing
Block or report user

Report or block viko16

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@viko16
viko16 / getDecimal.ts
Created Jun 20, 2019
获取一个数字的小数部分
View getDecimal.ts
/**
* 获取一个数字的小数部分,如果是整数则返回 0
*/
function getDecimal(num: number): number {
// 原理是先将数字乘以一定倍速,作为整数来计算
// 具体乘多大视乎小数点后有多少位 (10为基数的 x 次幂)
const BASE = Math.pow(10, (num.toString().split('.')[1] || '').length);
return num * BASE % BASE / BASE;
}
@viko16
viko16 / export.js
Last active May 13, 2019
兼容数组、对象解构的方法
View export.js
// 比如 API 暴露
function useApi () {
const a = 'a'
const b = 'b'
const c = 'c'
return Object.assign([ a, b, c ], { a, b, c }) // 务必数组在前,否则无法维护下标
}
// 使用时既可以
const [ a, b, c ] = useApi() // react hook 风格的数组解构
@viko16
viko16 / appendLink.js
Created Jul 11, 2018
插入链接的写法
View appendLink.js
@viko16
viko16 / Redirector.json
Last active May 30, 2018
Chrome 扩展 redirector 我的配置导出
View Redirector.json
{
"createdBy": "Redirector v3.1.0",
"createdAt": "2018-05-30T05:26:18.152Z",
"redirects": [
{
"description": "cdnjs.cloudflare.com",
"exampleUrl": "https://cdnjs.cloudflare.com/foo",
"exampleResult": "https://cdnjs.loli.net/foo",
"error": null,
"includePattern": "*//cdnjs.cloudflare.com/*",
@viko16
viko16 / sync.md
Created Mar 13, 2018
同步上游代码
View sync.md

同步上游代码

# 配置 remote 指向上游仓库
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
# 从上游获取
git fetch upstream
# 切回去自己的分支
@viko16
viko16 / pangujs-bookmarklet.js
Created Oct 14, 2016
召唤空格之神的小 bookmarklet
View pangujs-bookmarklet.js
javascript:void(function(url, script) {
script = document.body.appendChild(document.createElement('script'));
script.src = url;
script.onload = function() {pangu.spacingPage()};
}('//cdn.bootcss.com/pangu/3.2.1/pangu.min.js'))
@viko16
viko16 / ip-notation.js
Created Sep 8, 2016
IP 地址的多种玩法
View ip-notation.js
var ipStr = '180.97.33.107'
var arr = ipStr.split('.').map((el => parseInt(el, 10)))
// 十进制
var ten = arr[0] * Math.pow(2, 24) + arr[1] * Math.pow(2, 16) + arr[2] * Math.pow(2, 8) + arr[3]
console.log('http://' + ten)
// 十六进制
var sixteen = ten.toString(16)
@viko16
viko16 / screen-capture.js
Created Jul 18, 2016
用 PhantomJS 网页截图
View screen-capture.js
var page = require('webpage').create();
var url = 'http://ukn.me/#!/post/2016-07-13-Array%2520%25E9%259B%2586%25E5%2590%2588%25E6%2596%25B9%25E6%25B3%2595.md';
// 视窗大小
page.viewportSize = {
width: 1440,
height: 900
}
@viko16
viko16 / font.md
Last active Aug 14, 2016
挑选字体
View font.md

Inconsolata

  • Good: 一切都好,非常好看的等宽,第一眼很惊艳
  • Bad: 斜体不太好看,引号太斜几乎不能忍

Monaco

  • Good: 中规中矩,斜体好看
  • Bad: 总感觉是被拉高了,感觉怪怪的,暂时发现小写 m 挤在一起不太好看

Source Code Pro

  • Good: 字体饱满,i l 特别,0 中间带点
@viko16
viko16 / commit-message.md
Last active Jun 27, 2016
Commit message 的格式
View commit-message.md

Header

Header 部分只有一行,包括三个字段:

type(必需)、scope(可选)和subject(必需)。

type

用于说明 commit 的类别,只允许使用下面7个标识。

  • feat:新功能
You can’t perform that action at this time.