Skip to content

Instantly share code, notes, and snippets.

View xwartz's full-sized avatar
🎯
Focusing

xwartz xwartz

🎯
Focusing
View GitHub Profile
@xwartz
xwartz / interview-type.ts
Last active January 28, 2022 02:31
interview-type
/**
* 给定数组,转换为对象类型,键/值必须在给定数组中。
**/
// Example:
const tuple = ['tesla', 'model 3', 'model X', 'model Y'] as const
const result: TupleToObject<typeof tuple> // expected { tesla: 'tesla', 'model 3': 'model 3', 'model X': 'model X', 'model Y': 'model Y'}
@xwartz
xwartz / interview-type.ts
Created May 27, 2021 05:23
interview-type
/**
*
* Complete the following 2 types of 'CreateRequest' and 'GetParams'.
* 完善下述两个类型 'CreateRequest' 和 'GetParams'。
*
**/
// improve type of CreateRequest
type CreateRequest = unknown
@xwartz
xwartz / Interview-node.ts
Created May 27, 2021 05:22
Interview-node
/**
*
* Create a function that meets the following requirements:
* - Read files and folders from the specified directory.
* - Collects metadata about files or folders and returns it as an array.
* - Note whether the file has read access.
*
* 创建一个符合下述要求的函数:
* - 读取指定目录下的文件或文件夹,包含子文件夹
* - 收集文件的元信息并作为数组返回
@xwartz
xwartz / iterm2-solarized.md
Created November 4, 2019 12:05 — forked from kevin-smets/iterm2-solarized.md
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@xwartz
xwartz / getQueryString.js
Last active August 20, 2016 13:50
get query string from url
let getQueryString = (key, queryStr = location.search + location.hash) => {
let reg = new RegExp('(^|\\?|&)' + key + '=([^&]*)(\\s|&|$)', 'i')
return reg.test(queryStr) ? decodeURIComponent(RegExp.$2) : ''
}
'use strict';
let Ajax = {};
Ajax.xhr = () => {
let xhr, versions;
if(typeof XMLHttpRequest !== undefined) {
xhr = new XMLHttpRequest();
} else {
@xwartz
xwartz / test1111.js
Created October 14, 2015 13:01
天猫双11领优惠劵.. 自行滚动到页面底部 http://www.tmall.com/wow/act/14931/1111
var it = document.getElementsByClassName('mui-act-item-yhqbtn');
var i = 0;
function get(){
if(it.length <= i) return;
it[i++].click();
var c = document.getElementsByClassName('mui-dialog-close')[0];
c && c.click();
setTimeout(function(){get(); console.log(i)}, 500);
}
@xwartz
xwartz / convert-hex.js
Created September 14, 2015 02:21
颜色从十六进制转为 rgba
// 颜色 从十六进制转为 rgba
exports.convertHex = function(hex, opacity) {
hex = hex.replace('#', '');
r = parseInt(hex.substring(0, 2), 16);
g = parseInt(hex.substring(2, 4), 16);
b = parseInt(hex.substring(4, 6), 16);
result = 'rgba(' + r + ',' + g + ',' + b + ',' + opacity / 100 + ')';
return result;
};
@xwartz
xwartz / Model.js
Last active September 5, 2015 07:40
简单的 Model 实现
// 获取 GUID 方法, from Robert Kieffer
Math.guid = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16|0, v = c == 'x' ? r : (r&0x3|0x8)
return v.toString(16)
}).toUpperCase()
}
// Object.create 支持
@xwartz
xwartz / pubsub.js
Created September 4, 2015 17:08
发布订阅模式
var PubSub = {
// 订阅函数
subscribe: function (event, callback) {
// 创建事件存储对象
this._events = this._events || {}
// 添加回调函数
this._events[event] = this._events[event] || []
this._events[event].push(callback)
// 链式调用
return this