Skip to content

Instantly share code, notes, and snippets.

View beetcb's full-sized avatar
:octocat:
contributing

beet beetcb

:octocat:
contributing
View GitHub Profile
@beetcb
beetcb / semantic-commit-messages.md
Created August 23, 2020 14:35 — forked from joshbuchea/semantic-commit-messages.md
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@beetcb
beetcb / realDeepClone.js
Last active August 29, 2020 06:52
clone a object's flags
// using spread expression
let [one, two, three] = [...'12', { ...'abc' }]
const obj = { one, two, three }
function realDeepClone(obj, key, clone) {
if (!key) {
clone = Object.defineProperties({}, Object.getOwnPropertyDescriptors(obj))
} else {
clone[key] = Object.defineProperties(
{},
@beetcb
beetcb / GroupJson.js
Last active August 29, 2020 06:58
GroupJsonData.js
const grabRickAndMorty = {
info: {
count: 591,
pages: 30,
next: 'https://rickandmortyapi.com/api/character/?page=2',
prev: null,
},
results: [
{
id: 1,
@beetcb
beetcb / ArrayDeduplication.js
Last active August 29, 2020 07:00
Array Deduplication
array.filter(function (item, position) {
return array.indexOf(item) == position
})
// Maybe the easiest way => play with dot
// issue!!! => the float after 5 are all token by 5?
/*
function grabRandomDotWay(min, max, toNthDecimals) {
let result = null;
const range = max - min;
result = Math.trunc((range + 1) * Math.random() * (toNthDecimals && (Math.pow(10, toNthDecimals)) || 1));
// eg : result *= 0.01
result = result * Math.pow(0.1, toNthDecimals || 0) + '';
if (toNthDecimals) {
@beetcb
beetcb / WhatThisIs.js
Last active September 6, 2020 01:07
four Steps to master this
// 0.IS `addEventLister()` and `click` ... <EVENT> used?
// // => `this` === who triggered the <EVENT>
// 1.Is it an arrow function ?
// // => `this` in arrow function === `this` around(arrow function) the closest valid line
// 2.Is it `bind` `call` `apply`
// // => `this` === `this` inside those [key words method]
// 3.Is it called with prefix `.`
// // => `this` === who is in fornt of `.`
// // => no `.` added => `this` === window
const $ = console.log;
@beetcb
beetcb / readline.js
Last active January 12, 2021 15:24
keyPressListener.js
const readline = require('readline')
const read = readline.createInterface({
input: process.stdin,
output: process.stdout,
}).input
// Prase key-by-key
read.isRaw = true
  1. Copy ~/.gnupg folder from your Mac|GNU/Linux machine to C:\Users\username\AppData\Roaming\ folder on Windows(with win4gpg installed)
  2. The name .gnupg shall be changed to gnupg
@beetcb
beetcb / downloadThumbnail.js
Last active November 8, 2021 09:22
Thumbnail download script for a certain platform
/**
* Thumbnail download script for a certain platform
* @github https://gist.github.com/beetcb/75b511714cec347b9362639e6ff3f923
*/
;(async () => {
// Prerequisite
const rightToggle = document.querySelector('.right-panel-toggle')
if (rightToggle.classList.contains('active')) {
rightToggle.click()
await new Promise(res=>setTimeout(2000, res))
@beetcb
beetcb / findInheritedProps.console.js
Last active March 12, 2022 02:23
Find Inherited props from W3C Spec.
// Shall be excuted in W3C latest props table's webpage
// Current link https://www.w3.org/TR/CSS22/propidx.html
[...document.querySelectorAll("tbody>tr") ?? []].reduce((acc, tr) => {
const inheritance = tr.querySelector("td:nth-child(5)")
if (inheritance?.innerHTML === "yes\n") {
acc.push(tr.querySelector("td:nth-child(1)")?.innerText)
}
return acc