Skip to content

Instantly share code, notes, and snippets.

View yeyuguo's full-sized avatar
🎯
Focusing

Struggling Youth yeyuguo

🎯
Focusing
  • ...
  • China-BeiJing(Now)
View GitHub Profile
@yeyuguo
yeyuguo / add-proxy.js
Last active June 1, 2021 02:56
代理对象, 对函数执行进行 try catch 处理
// 简单工厂模式 - 创建对象
function createFactoryProxy(source, handler) {
// todo 扩展成为单例
const resultTmp = {}
var proxyInst = new Proxy(source, {
set(target, property, value, receiver) {
if (Reflect.has(resultTmp, property)) {
throw new Error('已经设置代理属性, 不能再次设置')
} else {
Reflect.defineProperty(resultTmp, property, {
@yeyuguo
yeyuguo / Dockerfile
Created February 3, 2021 07:57 — forked from remarkablemark/Dockerfile
Install node and npm with nvm using Docker.
# set the base image to Debian
# https://hub.docker.com/_/debian/
FROM debian:latest
# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# update the repository sources list
# and install dependencies
RUN apt-get update \
@yeyuguo
yeyuguo / kebabCase.js
Created December 16, 2020 08:29
驼峰命名转成 xx-xx 命名【kebabCase】
function kebabCase(str) {
const hyphenateRE = /([^-])([A-Z])/g;
return str
.replace(hyphenateRE, '$1-$2')
.replace(hyphenateRE, '$1-$2')
.toLowerCase();
}
@yeyuguo
yeyuguo / foo.js
Created October 30, 2020 03:42 — forked from vvgomes/foo.js
Ramda vs Lodash
var _ = require("lodash");
var R = require("ramda");
var companies = [
{ name: "tw", since: 1993 },
{ name: "pucrs", since: 1930 },
{ name: "tw br", since: 2009 }
];
var r1 = _(companies).chain()
@yeyuguo
yeyuguo / frontendDevlopmentBookmarks.md
Last active September 3, 2020 07:55 — forked from dypsilon/frontendDevlopmentBookmarks.md
A badass list of frontend development resources I collected over time.
@yeyuguo
yeyuguo / nginx.conf
Created September 3, 2020 07:51 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
@yeyuguo
yeyuguo / vue-webpack-chain-sass.js
Last active August 24, 2020 03:04
vue webpack webpack-chain sass loader 实现
{
chainWebpack: (config) =>{
// ...
// sass 处理
config.module.rules.delete('scss')
let scssRule = config.module.rule('scss')
.test(/\.scss$/);
[
{ name: 'vue-style-loader' },
@yeyuguo
yeyuguo / js获取滚动条的宽度
Created July 29, 2020 03:11 — forked from 337547038/js获取滚动条的宽度
js获取滚动条的宽度
判断滚动条的需求在弹窗插件中使用比较多,当弹窗添加overflow: hidden时,如果页面比较长的话,添加这个属性之后页面会有晃动。
为了增强用户体验,通过判断是否有滚动条而添加 margin-left 属性以抵消 overflow: hidden 之后的滚动条位置。
判断是否有滚动条的方法
function hasScrollbar() {
return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight);
}
计算滚动条宽度的方法
新建一个带有滚动条的 div 元素,通过该元素的 offsetWidth 和 clientWidth 的差值即可获得
function CopyToClipboard(option) {
var textToClipboard = option.text
function CreateElementForExecCommand (textToClipboard) {
var forExecElement = document.createElement ("div");
// place outside the visible area
forExecElement.style.position = "absolute";
forExecElement.style.left = "-10000px";
forExecElement.style.top = "-10000px";
// write the necessary text into the element and append to the document
forExecElement.textContent = textToClipboard;
@yeyuguo
yeyuguo / express_proxy.js
Created April 15, 2019 02:05
express server 和 代理 proxy 插件
var express = require('express');
var http = require('http')
var app = express();
var http_app = http.Server(app);
var proxy = require('express-http-proxy')
const remote = proxy("真实接口地址", {