Skip to content

Instantly share code, notes, and snippets.

View gera2ld's full-sized avatar
👽
what can I say

Gerald gera2ld

👽
what can I say
View GitHub Profile
@gera2ld
gera2ld / csv-parse.ts
Last active May 12, 2023 14:59
CSV parser
export function parseCsv(input: string, delimiter = ',') {
const scanQuoteEnd = (i: number) => {
for (; i < input.length; i = 1) {
const c = input[i];
if (c === '"') {
if (input[i 1] === '"') i = 1;
else break;
}
}
if (!input[i]) throw new Error('Quote is expected');
@gera2ld
gera2ld / README.md
Last active October 30, 2022 03:18
微博终结者

微博终结者

一键删除所有微博。

用法

@gera2ld
gera2ld / base64.js
Last active September 7, 2023 14:39
Base64 encoder / decoder with unicode support
// See https://github.com/gera2ld/js-lib
@gera2ld
gera2ld / brew-clean.sh
Created October 28, 2020 05:36
Clean unused packages installed by Homebrew
expected=(
# paste packages to keep here
aria2
deno
fzf
yarn
)
brew_clean() {
while
@gera2ld
gera2ld / katex.md
Last active October 2, 2024 08:34
Markmap demo
markmap
extraJs
npm:katex/dist/contrib/mhchem.min.js
  • katex
    • $x = {-b \pm \sqrt{b^2-4ac} \over 2a}$
  • $\ce{N2 3H2 -&gt;[Fe] 2NH3}$
@gera2ld
gera2ld / html2pdf.js
Created August 1, 2020 09:08
Create PDF from HTML via Puppeteer
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 July 9, 2020 04:03
Babel macro to create HTML from Markdown
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 April 30, 2020 15:12
tar extract from buffer
const { Readable } = require('stream');
const tar = require('tar');
export function string2stream(stringOrBuffer) {
const reader = new Readable();
reader.push(stringOrBuffer);
reader.push(null);
return reader;
}
@gera2ld
gera2ld / string-util.js
Last active August 4, 2022 14:57
JavaScript utilities
import { Readable } from 'stream';
export function string2stream(stringOrBuffer) {
const reader = new Readable();
reader.push(stringOrBuffer);
reader.push(null);
return reader;
}
export function stream2buffer(stream) {
@gera2ld
gera2ld / test-violentmonkey.user.js
Last active March 28, 2023 23:39
Test Violentmonkey functions
// ==UserScript==
// @name test script
// @namespace Violentmonkey Scripts
// @icon https://cn.gravatar.com/avatar/a0ad718d86d21262ccd6ff271ece08a3?s=80
// @homepage https://gist.github.com/gera2ld/1c14672b77ade31ad8f0984725de18fc
// @resource baidu https://www.baidu.com/img/baidu_jgylogo3.gif
// @resource text data:text/plain,hello,world
// @resource mochaCss https://cdn.jsdelivr.net/npm/[email protected]/mocha.min.css
// @resource cjk https://cdn.jsdelivr.net/gh/intellilab/translator.user.js/README.md
// @run-at document-start