Skip to content

Instantly share code, notes, and snippets.

View guiqide's full-sized avatar
🎯
Focusing

Gabriel B guiqide

🎯
Focusing
View GitHub Profile
@guiqide
guiqide / ghost-btn.css
Created November 12, 2019 09:35
ghost-btn
*
*:after
*:before
box-sizing border-box
:root
--bg #fafafa
body
display flex
@guiqide
guiqide / showElementAttribute.js
Created November 12, 2019 06:51
showElementAttribute
// 查看元素信息
(function SpyOn() {
const _id = 'spyon-container',
_posBuffer = 3;
function init() {
document.body.addEventListener('mousemove', glide);
document.body.addEventListener('mouseover', show);
document.body.addEventListener('mouseleave', hide);
@guiqide
guiqide / treeNode.js
Created September 19, 2019 02:06
一道将路径转为树结构的题
class Tree {
constructor(arr) {
let obj = {}
let subObj = obj
arr.forEach((item, index) => {
if (index == arr.length - 1) {
subObj['leaves'] = [item]
} else {
subObj[item] = {}
subObj = subObj[item]
@guiqide
guiqide / Intl.js
Created September 19, 2019 02:05
国际化测试题
class Intl {
constructor(set) {
this.set = set
}
get(keyStr) {
const keys = keyStr.split('.')
let value = this.set
for (let i = 0; i < keys.length; i++) {
if (value[keys[i]]) {
value = value[keys[i]]
@guiqide
guiqide / thousands.js
Last active February 14, 2023 03:02
正则——将数字增加千分位
// 小数部分也会被加千分位
// const regex = /(?=(\B\d{3})+(?!\d))/gm;
// 小数部分不转换
const regex = /(^|\s)\d+/g, (m) => m.replace(/(?=(?!\b)(\d{3})+$)/g;
const str = `1234567890`;
const subst = `,`;
// The substituted value will be contained in the result variable
@guiqide
guiqide / transformQuery.js
Created September 17, 2019 13:40
正则实现将参数转对象和取出某参数的值
const str = 'https://www.baidu.com?name=jawil&age=23'
function transformQuery(url) {
const r = new RegExp(`[?&]([a-zA-Z]+)=([^&]*)`, 'g')
let obj = {}
let match = r.exec(url)
while (match !== null) {
obj[match[1]] = match[2]
match = r.exec(url)
}
return obj
@guiqide
guiqide / js-template.js
Last active September 19, 2019 02:08
正则——实现js模板引擎
// 别看这个模板引擎代码很少,但是活用了正则、将字符串转为可以行代码两个知识点
const a = {
a: 1,
b: {
c: 2,
e: ['Array']
}
}
const tpl = `你好{{ a ? '真' : '假'}}
@guiqide
guiqide / getSlackObject.js
Created May 7, 2019 09:05
[getSlackObject] 获取可能不存在的属性的值
function baseGet(object, path) {
path = isKey(path, object) ? [path + ''] : baseCastPath(path);
var index = 0,
length = path.length;
while (object != null && index < length) {
object = object[path[index++]];
}
return (index && index == length) ? object : undefined;
@guiqide
guiqide / removeRedlock.php
Created December 29, 2018 03:32
删除分布锁
private function __removeRedlock()
{
Redis::del("{$this->redisKey}_redlock");
}
@guiqide
guiqide / addRedlock.php
Created December 29, 2018 03:32
增加分布锁,支持等待锁
/**
* 加锁——允许设置最长等待时间,单位秒
* 在等待期内持续争锁
*/
private function __addRedlock($expire = 3)
{
$time = time();
$lock = null;
do {
$lock = Redis::set("{$this->redisKey}_redlock", true, 'ex', 1, 'nx');