Skip to content

Instantly share code, notes, and snippets.

Avatar
🙉
stack overflowed

Gerald gera2ld

🙉
stack overflowed
View GitHub Profile
@gera2ld
gera2ld / base64.js
Last active Feb 1, 2021
Base64 encoder / decoder with unicode support
View base64.js
function base64decode(base64) {
const bin = atob(base64);
const len = bin.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i += 1) {
bytes[i] = bin.charCodeAt(i);
}
const decoder = new TextDecoder();
return decoder.decode(bytes);
}
@gera2ld
gera2ld / brew-clean.sh
Created Oct 28, 2020
Clean unused packages installed by Homebrew
View brew-clean.sh
expected=(
# paste packages to keep here
aria2
deno
fzf
yarn
)
brew_clean() {
while
@gera2ld
gera2ld / app.svelte
Created Sep 27, 2020
Clipboard svelte component
View app.svelte
<script>
import Clipboard from './clipboard.svelte';
</script>
<Clipboard let:copy let:copied text="some text">
{#if copied}
<span>Copied</span>
{:else}
<button {copy}>Copy</button>
{/if}
@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 Feb 25, 2021
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,
};