Skip to content

Instantly share code, notes, and snippets.

View muzi131313's full-sized avatar

roastwind muzi131313

View GitHub Profile
// from: https://mp.weixin.qq.com/s/qxi_28ozTZqjLeJNlpR6rA
// 来自https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem.
function base64ToBytes(base64) {
const binString = atob(base64);
return Uint8Array.from(binString, (m) => m.codePointAt(0));
}
// 来自https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem.
function bytesToBase64(bytes) {
const binString = String.fromCodePoint(...bytes);
@muzi131313
muzi131313 / loadScript
Created November 24, 2021 03:41
动态加script
function loadScript(url, attributesParam, optsParam) {
var attributes = attributesParam || {};
// optional
var opts = optsParam || {};
var script = document.createElement('script');
// default value
if (attributes.defer === undefined) {
attributes.defer = true;
}
@muzi131313
muzi131313 / handle_duplicate_link
Created May 13, 2021 07:01
remove duplicate query param in link address
function includeKey(objectA, objectB) {
if (!objectA || !objectB) {
return false;
}
const objectAKeys = Object.keys(objectA);
const objectBKeys = Object.keys(objectB);
if (!objectBKeys || !objectBKeys) {
return false;
}
const _include = objectBKeys.some(objectBKey => {
@muzi131313
muzi131313 / compare_array
Last active May 13, 2021 06:57
compare two array, eg: [1, {a: 123}]
function copyArray(value) {
return JSON.parse(JSON.stringify(value))
}
/**
* @name isArrayEqual
* @param {Array} arrayA 数组A
* @param {Array} arrayB 数组B
* @description 比较两个数组,内容可以顺序不一致
* @returns
// http://js.jsrun.net/ScLKp/edit
class EventBus {
constructor() {
/**
* 构造函数需要存储的 event 事件
*/
this.events = this.events || new Object();
}
}
@muzi131313
muzi131313 / isInChina
Created October 27, 2020 11:40
判断是否在国内
function isInChina(cb) {
return new Promise((resolve, reject) => {
try {
let url = "//graph.facebook.com/feed?callback=h"
let xhr = new XMLHttpRequest()
let called = false
xhr.open("GET", url)
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
called = true
var setContextOption = (newCtx, {
smoothEnabled = true,
smoothQuality = 'high'
} = {}) => {
newCtx.imageSmoothingEnabled = smoothEnabled // 图片平滑, 默认为 true
newCtx.msImageSmoothingEnabled = smoothEnabled
newCtx.webkitImageSmoothingEnabled = smoothEnabled
newCtx.mozImageSmoothingEnabled = smoothEnabled
newCtx.imageSmoothingQuality = smoothQuality // 调整平滑质量
newCtx.msImageSmoothingQuality = smoothQuality
@muzi131313
muzi131313 / 01-gulpfile.js
Created January 30, 2016 17:56 — forked from markgoodyear/01-gulpfile.js
Comparison between gulp and Grunt. See http://markgoodyear.com/2014/01/getting-started-with-gulp/ for a write-up.
/*!
* gulp
* $ npm install gulp-ruby-sass gulp-autoprefixer gulp-cssnano gulp-jshint gulp-concat gulp-uglify gulp-imagemin gulp-notify gulp-rename gulp-livereload gulp-cache del --save-dev
*/
// Load plugins
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
autoprefixer = require('gulp-autoprefixer'),
cssnano = require('gulp-cssnano'),
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var bower = require('main-bower-files');
gulp.task('bower', function () {
return gulp.src(bower())
.pipe(concat('vendor.js'))
.pipe(uglify())
.pipe(gulp.dest('/build/scripts'));