Skip to content

Instantly share code, notes, and snippets.

View miaopeng's full-sized avatar
🎯
🎧 🎨 🎦 🚶

Peng Miao (mios) miaopeng

🎯
🎧 🎨 🎦 🚶
  • 观云
  • Beijing, China
View GitHub Profile
@miaopeng
miaopeng / index.html
Created April 28, 2022 08:40 — forked from iamsaso/index.html
GraphiQL with JWT
<!DOCTYPE html>
<html>
<head>
<style>
body {
height: 100%;
margin: 0;
width: 100%;
overflow: hidden;
}
//**dataURL to blob**
function dataURLtoBlob(dataurl) {
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], {type:mime});
}
@miaopeng
miaopeng / test.js
Created February 24, 2021 09:33 — forked from smalljam/test.js
xlsx library patch, so we can make bold cells and align them to the right
var XLSX = require('xlsx')
function Workbook() {
this.SheetNames = ['Report'];
this.Sheets = {};
}
var wb = new Workbook();
var ws = {
// /swr/project.js
import useSWR, { mutate } from 'swr'

export async function fetchProject (id) {
  mutate(`/api/project/${id}`, fetch(`/api/project/${id}`))
}

export default function useProject (id) {
 // don't pass the fetcher so it won't fetch
@miaopeng
miaopeng / observer.js
Last active May 21, 2020 06:37
监控 document.title 改变
new MutationObserver(function(mutations) {
console.log("title changed!", mutations);
}).observe(
document.querySelector('title'),
{ childList: true }
);
@miaopeng
miaopeng / index.html
Created January 23, 2020 04:32
svg-pie-chart
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>环形图</title>
</head>
<body>
<div id="div"></div>
<script>
function getUUID() {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#ff0000';
ctx.fillRect(0,0,8,10);
const b64 = canvas.toDataURL().replace('data:image/png;base64,', '');
const bin = window.atob(b64);
return bin2hex(bin.slice(-16, -12));
}
@miaopeng
miaopeng / getBase64
Created January 15, 2019 09:15
FileReader
function getBase64(img, callback) {
const reader = new FileReader();
reader.addEventListener('load', () => callback(reader.result));
reader.readAsDataURL(img);
}
@miaopeng
miaopeng / upload.js
Created January 15, 2019 08:57
eggjs upload
'use strict';
const fs = require('mz/fs');
const path = require('path');
const Controller = require('egg').Controller;
const pump = require('mz-modules/pump');
class UploadController extends Controller {
async pic() {
const { ctx } = this;
require('fs').stat(BINPATH + 'selenium.jar', function (err, stat) { // got it?
if (err || !stat || stat.size < 1) {
require('selenium-download').ensure(BINPATH, function(error) {
if (error) throw new Error(error); // no point continuing so exit!
console.log('✔ Selenium & Chromedriver downloaded to:', BINPATH);
});
}
});