Skip to content

Instantly share code, notes, and snippets.

🙉
stack overflowed

Gerald gera2ld

🙉
stack overflowed
View GitHub Profile
@gera2ld
gera2ld / html2pdf.js
Created Aug 1, 2020
Create PDF from HTML via Puppeteer
View html2pdf.js
const fsPromises = require('fs').promises;
const puppeteer = require('puppeteer');
async function main() {
const browser = await puppeteer.launch({
headless: true,
args: ['--proxy-server=socks5://127.0.0.1:2020'],
});
const page = await browser.newPage();
await page.goto('https://gera2ld.space', { waitUntil: 'networkidle0' });
@gera2ld
gera2ld / converter.js
Created Jul 9, 2020
Babel macro to create HTML from Markdown
View converter.js
function getConverter(showdown) {
showdown.setFlavor('github');
showdown.subParser('runExtension', (ext, source, options, globals) => {
let text = source;
if (ext.filter) {
text = ext.filter(text, globals.converter, options, globals);
}
return text;
});
return new showdown.Converter({
@gera2ld
gera2ld / tar-extract-from-buffer.js
Last active Apr 30, 2020
tar extract from buffer
View tar-extract-from-buffer.js
const { Readable } = require('stream');
const tar = require('tar');
export function string2stream(stringOrBuffer) {
const reader = new Readable();
reader.push(stringOrBuffer);
reader.push(null);
return reader;
}
View setting-input.vue
<template>
<input v-if="ready" type="text" :class="{'has-error': error}" v-model="value">
</template>
<script>
import { debounce } from '#/common';
import options from '#/common/options';
import hookSetting from '#/common/hook-setting';
export default {
@gera2ld
gera2ld / string-util.js
Last active Apr 30, 2020
JavaScript utilities
View string-util.js
const { Readable } = require('stream');
export function string2stream(stringOrBuffer) {
const reader = new Readable();
reader.push(stringOrBuffer);
reader.push(null);
return reader;
}
export function escapeRegExp(string) {
@gera2ld
gera2ld / storage.js
Created Sep 30, 2019
Storage wrapper
View storage.js
export function getStorage(provider) {
return initialize();
function initialize() {
if (!provider) provider = window.localStorage;
return {
get,
set,
bind,
};
@gera2ld
gera2ld / git-update.py
Created May 18, 2019
Update all git repositories in a directory
View git-update.py
import os
import sys
import time
from queue import Queue, Empty
from threading import Thread
from git import Repo
root = sys.argv[1]
concurrency = 10
@gera2ld
gera2ld / test-violentmonkey.user.js
Last active May 26, 2020
Test Violentmonkey functions
View test-violentmonkey.user.js
// ==UserScript==
// @name test script
// @namespace Violentmonkey Scripts
// @icon https://cn.gravatar.com/avatar/a0ad718d86d21262ccd6ff271ece08a3?s=80
// @resource baidu https://www.baidu.com/img/baidu_jgylogo3.gif
// @resource text data:text/plain,hello,world
// @resource mochaCss https://cdn.jsdelivr.net/npm/mocha@7.0.1/mocha.min.css
// @run-at document-start
// @grant GM_getValue
// @grant GM_setValue
@gera2ld
gera2ld / loadmore.js
Created Feb 17, 2017
`v-loadmore` directive for Vue.js 2
View loadmore.js
import Vue from 'vue';
import throttle from 'lodash.throttle';
Vue.directive('loadmore', {
bind(el, binding, vnode) {
let value = binding.value || {};
let callback;
if (typeof value === 'function') {
callback = value;
value = {};
@gera2ld
gera2ld / polyfill.js
Last active Feb 7, 2017
Simple polyfills for JavaScript
View polyfill.js
function polyfill(obj, key, value) {
if (!obj[key]) Object.defineProperty(obj, key, {
value,
configurable: true,
writable: true,
});
}
// Polyfill Object.assign
polyfill(Object, 'assign', (obj, ...args) => {
You can’t perform that action at this time.