Skip to content

Instantly share code, notes, and snippets.

View mactanxin's full-sized avatar
😆
happy coding

Xin Tan mactanxin

😆
happy coding
  • San Jose
  • 19:32 (UTC +08:00)
View GitHub Profile
$margin-unit: 4;
$padding-unit: 4;
$spacing-modifiers: (
'ma': margin,
'mx': margin,
'my': margin,
'mt': margin-top,
'mr': margin-right,
'mb': margin-bottom,
let retry = function(fn, maxTime) {
let counter = 0;
function execFunc () {
return new Promise((resolve, reject) => {
console.log(`第${counter}次请求`);
resolve(fn);
}).then(res => {
return Promise.resolve(res);
}).catch(e=>{
counter += 1;
function generatePromiseFunc(index) {
return function () {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(index)
resolve(index)
}, 1000)
})
}
}
@mactanxin
mactanxin / fib.js
Created June 22, 2020 08:07 — forked from guxuerui/fib.js
菲波那切数列
const fib = (num) => {
if (num <= 0) return 0;
if (num === 1 || num === 2) return 1;
if (num > 2) {
let prev = 1, next = 1;
for (let i = 3; i <= num; i++) {
let sum = prev + next;
prev = next;
next = sum;
}
String.prototype.capFirstLetter = function() {
let [first, ...rest] = this.split('');
return first.toUpperCase() + rest.join('');
};
Array.prototype.equals = function (arr) {
if(arr.length !== this.length) {
return false;
}
for (var i = arr.length - 1; i >= 0; i--) {
if (this[i] !== arr[i]) {
return false;
}
}
return true;
git log --oneline --format=%B -n 1 HEAD | head -n 1
git log --oneline --format=%B -n 1 HEAD
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
0.0 0.0
1.1 1.1
3.5 4.5
2.2 2.2
0.1 1.0
2.1 1.2
3.1 1.3