Skip to content

Instantly share code, notes, and snippets.

View legend80s's full-sized avatar
🎯
Focusing

legend80s

🎯
Focusing
  • Alibaba
  • Beijing
View GitHub Profile
@legend80s
legend80s / table2JSObject.js
Created November 19, 2022 06:25
Transform HTML `table` element to JS Object.
/**
* Transform HTML `table` element to JS Object.
* @param {HTMLTableElement} table
* @returns {{ caption: string; rows: Array<{ [key: string]: string }>; }}
*/
function table2JSObject(table) {
const caption = table.caption ? table.caption.textContent.trim() : '';
const titles = [...table.querySelectorAll('th')].map(th => {
const innerHTML = th.innerHTML;
@legend80s
legend80s / .bash_profile
Created May 12, 2020 09:55 — forked from jonsuh/.bash_profile
Bash echo in color
# ----------------------------------
# Colors
# ----------------------------------
NOCOLOR='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
@legend80s
legend80s / package-json.d.ts
Created August 24, 2019 05:47 — forked from iainjreid/package-json.d.ts
A Typescript type definition for NPM package files
export interface IPackageJSON extends Object {
readonly name: string;
readonly version?: string;
readonly description?: string;
readonly keywords?: string[];
@legend80s
legend80s / compile.js
Created June 17, 2018 13:04
compile string to DOM
/**
* 将字符串编译为 DOM 结构
* @deprecated 请注意,不要用该函数,因为 compile('<div></div><p></p>') 会编译成嵌套结构:<p><div></div></p>
* @public
* @param {String} domString
* @return {HTMLElement}
* @throws {Error} 如果输入不是合法的 DOM 字符串
*
* @example
* compile('<div><p><a><em></em></a></p></div>')
@legend80s
legend80s / q-race.es6
Created May 7, 2018 08:58 — forked from jrencz/q-race.es6
Quick attempt to add spec-compliant race method to Angular $q
(function () {
'use strict';
angular
.module('q.race', [])
.config(function ($provide) {
$provide.decorator('$q', function ($delegate) {
$delegate.race = promises => $delegate((resolve, reject) => {
const bind = promise => {
@legend80s
legend80s / MethodInvoker.php
Created July 18, 2017 06:34
Call protected/private static method of a class. Used usually in Unit Test.
<?php
trait MethodInvoker {
/**
* Call protected/private static method of a class.
*
* @param string $class - class name that we will run method on
* @param string $methodName - method name to call
* @param array $parameter - parameter to pass into method
*
* @return mixed - original method's return
@legend80s
legend80s / sublime-text-scopes.md
Created July 5, 2017 08:57 — forked from J2TEAM/sublime-text-scopes.md
Sublime Text 2/3: Snippet scopes

Here is a list of scopes to use in Sublime Text 2/3 snippets -

ActionScript: source.actionscript.2
AppleScript: source.applescript
ASP: source.asp
Batch FIle: source.dosbatch
C#: source.cs
C++: source.c++
Clojure: source.clojure
@legend80s
legend80s / sublime-eslint-installation-guide.md
Last active June 29, 2017 06:34
Sublime eslint installation guide

package control install

  1. 安装 sublimelinter
  2. 安装 sublimelinter-eslint # 重启 sublime
  3. 用户设置 SublimeLinter.sublime-settings
{
    "user": {
        "debug": false,
        "delay": 0.25,
        "error_color": "D02000",
@legend80s
legend80s / os-loading-indicator.js
Last active November 19, 2020 17:21
Show spinner for you every pending HTTP requests
import angular from 'angular';
import 'angular-spinner';
function loadingInterceptor($q, $injector) {
let http;
let usSpinnerService;
let timeout;
return {
request(config) {
@legend80s
legend80s / detectNetworkAccessibility.js
Last active April 2, 2017 13:30
Browser JavaScript snippet to detect network accessibility
/**
* `onDisconnected` will be called when network disconneted
* The script must be run in the console of `TEST_URL`
*/
function detectNetworkAccessibility({ TEST_URL, DETECT_INTERVAL = 30 * 1000, TIMEOUT = 3 * 1000 }, onDisconnected = alert) {
const RETRY_INTERVAL = 5 * 1000;
console.log(`Detecting network accessibility by fetching ${TEST_URL} at every ${DETECT_INTERVAL / 1000}s`);
timeoutableFetch(fetch(TEST_URL), { TIMEOUT })