Skip to content

Instantly share code, notes, and snippets.

View black-black-cat's full-sized avatar

bcatb black-black-cat

View GitHub Profile
@black-black-cat
black-black-cat / a.js
Last active July 13, 2019 07:23
rgb to hex, hex to rgb
const rgbToHex = (text) => {
let arr = text.split(/[^0-9.]+/).slice(1, -1)
let r = +arr[0]
let g = +arr[1]
let b = +arr[2]
let a = +arr[3]
let v = (r << 16) + (g << 8) + b
let hex = ('00000' + v.toString(16)).slice(-6)
return a == null ? hex : {hex, a}
}
@black-black-cat
black-black-cat / a.js
Last active July 16, 2019 02:55
deep clone
const fromObj = (source = {}) => Object.keys(source).map(k => source[k])
const k = {
a: 1
}
const data = {
start: k,
a: [],
b: [1, 2, 3],
c: [{ foo: 'bar' }],
let floor = Math.floor.bind(null)
let factors = [1, 1000, 1000 * 60, 1000 * 60 * 60, 1000 * 60 * 60 * 24]
function parseMs (input, {withDay = false}) {
let ms = input % 1000
let { h, m, s } = parseSec(floor(input / 1000))
if (withDay) {
let d = floor(h / 24)
h = h % 24
! Put user rules line by line in this file.
! See https://adblockplus.org/en/filter-cheatsheet
||wikipedia.org
||jsfiddle.net
.wikipedia.org
||hackmd.io
@black-black-cat
black-black-cat / index.html
Created May 14, 2019 06:31
Easier Error Handling Using Async/Await
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Hello world!</h1>
<script src="sureThing.js"></script>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Hello world!</h1>
<script src="script.js"></script>
@black-black-cat
black-black-cat / backup.js
Last active May 10, 2019 08:03
getCursor
console.log('Hello World!');
/**
*
* @param {string|number} direIndex direction name or direction index
* @param {number} [angle]
*
*/
function getCursor (direIndex, angle = 0) {
let direNames = ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw']
@black-black-cat
black-black-cat / Get week number
Last active January 30, 2019 08:13 — forked from IamSilviu/Get week number
JavaScript Get week number.
Date.prototype.getWeek = function () {
var onejan = new Date(this.getFullYear(), 0, 1);
var today = new Date(this.getFullYear(), this.getMonth(), this.getDate());
return Math.ceil((((today - onejan) / 86400000) + onejan.getDay() + 1) / 7);
};
var myDate = new Date("2001-02-02");
myDate.getWeek(); //=> 5
@black-black-cat
black-black-cat / index.html
Created December 26, 2018 02:22
generate verification code
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GistRun</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Hello world!</h1>
<script src="script.js"></script>
@black-black-cat
black-black-cat / formatCurrTime.js
Last active March 9, 2020 02:01
format time, format duration
const padNum = require('padNum')
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()