Skip to content

Instantly share code, notes, and snippets.

View wangsijie's full-sized avatar

wangsijie wangsijie

View GitHub Profile
View node-canvas-blur.js
const blur = 3; // 模糊半径
const url = 'https://user-images.githubusercontent.com/5717882/100448394-2325e300-30ed-11eb-9d9f-f5c3042e9ff1.png'; // 图片
const canvas = Canvas.createCanvas(width, height);
const ctx = canvas.getContext('2d');
const image = await Canvas.loadImage(url);
ctx.drawImage(image, 0, 0);
const imageData = ctx.getImageData(0, 0, width, height);
ctx.clearRect(0, 0, width, height);
const { data } = imageData;
View decide-font-color.js
function decideFontColor(background) {
const red = parseInt(background.substr(0, 2), 16);
const green = parseInt(background.substr(2, 2), 16);
const blue = parseInt(background.substr(4, 2), 16);
if ((red * 0.299 + green * 0.587 + blue * 0.114) > 186) {
return '#000000';
}
return '#ffffff';
};
View express-return-buffer.js
import stream from 'stream';
app.get('/', function (req, res) {
const buffer = Buffer.from('p8AuXbAKFihL9N1H4aYi7w==', 'base64');
const bufferStream = new stream.PassThrough();
bufferStream.end(buffer);
bufferStream.pipe(res);
});
View vercel-pdf-js.md

在Vercel里直接运行pdf.js包

const pdfjsLib = require("pdfjs-dist/es5/build/pdf.js");

会报下面的错:

Unhandled rejection: Error: Setting up fake worker failed: "Cannot find module './pdf.worker.js'
View axios-upload-file-using-form-data.js
const FormData = require('form-data');
const axios = require('axios');
const file = (await axios.get('https://test.com/test.jpg', { responseType: 'stream' })).data;
const formData = new FormData();
formData.append('file', file);
const res = await axios.post(
'https://test.com/upload',
formData,
{
View read-dot-env.sh
export $(grep -v '^#' .env | xargs)
View set-nextcloud-chunk-size.sh
sudo -u www-data php occ config:app:set files max_chunk_size --value 1000000
View get-git-file-create-time.sh
git log --diff-filter=A --follow --format=%aD -1 -- FILENAME
View see-things-differently.md

You don't travel to see different things, you travel to see things differently.