Skip to content

Instantly share code, notes, and snippets.

View zhiqiang21's full-sized avatar
🇨🇳
Happy

ZhiQiangHou zhiqiang21

🇨🇳
Happy
View GitHub Profile
@zhiqiang21
zhiqiang21 / gist:60317bcc198a703e1c158b6e851ec524
Last active November 9, 2019 04:23
获取网络请求各个阶段的信息
import { urlQuery } from './url';
(function(){
const entryList = performance && performance.getEntries && performance.getEntries();
const country = urlQuery.location_country;
const cityid = urlQuery.location_cityid;
let linkPerformance = null;
@zhiqiang21
zhiqiang21 / run.sh
Created May 4, 2018 02:11
npm设置淘宝镜像.sh
npm set registry https://registry.npm.taobao.org # 注册模块镜像
npm set disturl https://npm.taobao.org/dist # node-gyp 编译依赖的 node 源码镜像
## 以下选择添加
npm set chromedriver_cdnurl http://cdn.npm.taobao.org/dist/chromedriver # chromedriver 二进制包镜像
npm set operadriver_cdnurl http://cdn.npm.taobao.org/dist/operadriver # operadriver 二进制包镜像
npm set phantomjs_cdnurl http://cdn.npm.taobao.org/dist/phantomjs # phantomjs 二进制包镜像
npm set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass # node-sass 二进制包镜像
npm set electron_mirror http://cdn.npm.taobao.org/dist/electron/ # electron 二进制包镜像
npm set selenium_cdnurl=http://npm.taobao.org/mirrors/selenium
@zhiqiang21
zhiqiang21 / mdnTozh-cn.js
Last active March 25, 2021 10:49
MDN搜索结果自动跳转中文简体页面
// ==UserScript==
// @name MDN自动转化中文简体
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match *://developer.mozilla.org/*
// @run-at document-end
// @grant none
// ==/UserScript==
@zhiqiang21
zhiqiang21 / .eslintrc.js
Created June 9, 2017 03:41
.eslintrc.js 配置文件
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"amd": true,
"mocha": true,
"commonjs": true
},
"parser": "babel-eslint",
@zhiqiang21
zhiqiang21 / middleware.js
Created April 13, 2017 02:24
next 中间件模式的实现
function Middleware() {
this.cache = [];
this.options = null; // 缓存options
}
Middleware.prototype.use = function (fn) {
if (typeof fn !== 'function') {
throw 'middleware must be a function';
}
this.cache.push(fn);
@zhiqiang21
zhiqiang21 / 移动端H5图片压缩上传.md
Created March 21, 2017 03:34
移动端h5图片压缩上传

移动端H5图片压缩上传

大体的思路是,部分API的兼容性请参照caniuse

  1. 利用FileReader,读取blob对象,或者是file对象,将图片转化为data uri的形式。
  2. 使用canvas,在页面上新建一个画布,利用canvas提供的API,将图片画入这个画布当中。
  3. 利用canvas.toDataURL(),进行图片的压缩,得到图片的data uri的值
  4. 上传文件。

步骤1当中,在进行图片压缩前,还是对图片大小做了判断的,如果图片大小大于200KB时,是直接进行图片上传,不进行图片的压缩,如果图片的大小是大于200KB,则是先进行图片的压缩再上传:

@zhiqiang21
zhiqiang21 / check_css3_property.js
Created March 8, 2017 07:03
js判断浏览器是否支持css3属性
/**
* 判断浏览器是否支持某一个CSS3属性
* @param {String} 属性名称
* @return {Boolean} true/false
* @version 1.0
*/
function supportCss3(style) {
var prefix = ['webkit', 'Moz', 'ms', 'o'],
i,
@zhiqiang21
zhiqiang21 / jsbeautify.js
Last active September 5, 2017 14:20
.jsbeautifyrc配置文件
{
// The plugin looks for a .jsbeautifyrc file in the same directory as the
// source file you're prettifying (or any directory above if it doesn't exist,
// or in your home folder if everything else fails) and uses those options
// along the default ones.
// Details: https://github.com/victorporof/Sublime-HTMLPrettify#using-your-own-jsbeautifyrc-options
// Documentation: https://github.com/einars/js-beautify/
"html": {
"allowed_file_extensions": ["htm", "html", "xhtml", "shtml", "xml", "svg"],
@zhiqiang21
zhiqiang21 / 卸载pycharm系列.js
Created January 8, 2017 16:36
卸载Jetbrains系列
#!/usr/bin/env bash
set -x
# Clear Application Saved States JetBrains
rm -rfv ~/Library/Saved\ Application\ State/com.jetbrains.*
# PhpStorm
rm -fv /usr/local/bin/pstorm
rm -rfv ~/Library/Preferences/WebIde?0
rm -rfv ~/Library/Caches/WebIde?0
@zhiqiang21
zhiqiang21 / 压缩图片上传.html
Last active February 2, 2021 08:37
javascript压缩图片然后上传
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<title>移动端图片压缩上传demo</title>
<style>
*{margin: 0;padding: 0;}
li{list-style-type: none;}
a,input{outline: none;-webkit-tap-highlight-color:rgba(0,0,0,0);}