Skip to content

Instantly share code, notes, and snippets.

Avatar
🎅

Claus Wahlers claus

🎅
View GitHub Profile
@claus
claus / base64fixer.js
Created Aug 25, 2021
Fixes base64 casing in case it got lost
View base64fixer.js
const b64alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
const b64 = 'd2ugzwnobyb3zsbly2hvihdligvjag8gd2ugzwnobyb3zsbly2hvihdligvjag8gcndligvjag8gd2ugsgvsbg8/igvjag8gd2ugzwnobyb3zsbly2hvihdligvjag8gd2ugzwnobyakd2ugzwnobyb3zsbly2hvifdlignhbibtyxlizsbzzw5kigegbwvzc2fnzsb3zsakd2ugzwnobyb3zsbly2hvihdligvjag8gd2ugzwnobyb3zsbly2hvihdligvjag8gcndligvjag8gd2ugzwnobyb3zsb3agvyzsbhcmugd2u/igvjag8gd2ugzwnobyakd2ugzwnobyb3zsbzb21lag93igvjag8gd2ugzwnobyb3zsbly2hvihdligvjag8gcndligvjag8gd2ugzwnobyb3zsbly2hvihdligvjag8gd2ugzwnobyb3zsbly2hviap3zsbly2hviekgc2vligegbglnahqgynv0igl0j3mgzg9lc250igxvb2sgcmlnahqgiap3zsbly2hvihdligvjag8gd2ugzwnobyb3zsbly2hvihdligvjag8gd2ugzwnobyakd2ugzwnobyb3zsbly2hvienhbib5b3ugagvhcibtzt8gd2ugzwnobyb3zsbly2hvia=='.toUpperCase();
const b64arr = b64.split('');
function getBestMatch(quad) {
const scores = [];
let cancelled = false;
for (let i = 0; i < 16; i++) {
const bin = i.toString(2).padStart(4, '0');
const res = new Array(3).fill(0);
View outguess.js
/*
Make sure you have Node.JS and Outguess.app installed.
Copy this file as 'outguess.js' into an empty folder.
In that folder, run:
npm init
npm i guess-file-type tmp png-js
Change OUTGUESS_APP, WORK_DIR, SOURCE and VERBOSE below as you need them.
@claus
claus / example.js
Last active Jan 24, 2021
Proxy wrapper for tweenjs that automatically starts/stops requestAnimationFrame so you don't have to
View example.js
import { tween } from './tween';
tween({ x: 0 })
.to({ x: 1 }, 200)
.onStart(() => { console.log('onStart') })
.onStop(() => { console.log('onStop') })
.onComplete(() => { console.log('onComplete') })
.onUpdate(tweenObj => { console.log('onUpdate', tweenObj.x) })
.start(1000)
@claus
claus / sbRichTextReactRenderer.js
Last active Aug 1, 2020
Storyblok Rich Text Renderer for React
View sbRichTextReactRenderer.js
/*
Usage:
storyblokRichTextRenderer(document, {
blokResolvers: {
// Resolve a blok to a custom React component
['test_blok']: props => <TestBlok {...props} />
},
nodeResolvers: {
// Resolve a node to a custom React component
View gist:7f80a5704a95b5d69925b5caaaada6a0
1D=@%:$D="$=E5H9HAI=E// 32 G.UBOBJ7I1M3I.H8EE5A3D3B / ,D F3J3;D?DIAP=YBW8S2P0P""D &1V9^;_A[AZ;S1V'=RCYEYMTMSDKCP=R&@ENSPSVNVMIB@E&JBWLYL_H^FP>JB":MO.0:V.19;3;0;19,1,0;0;5
2F.I=1TO7:V=?D:D=D+1:F.J=32TOV:X=?D*8+128:Y=D?1*12-288:D=D+2:PL.5+(J<33),X,Y:N.:PL.&85,X-8*(I>1),Y+4:N.:F.I=0TO32:MOV.640,512:PL.145,416+I*2,0:N.:GC.0,0:F.I=0TO900:PL.69,RND(1279),RND(1023):N.
@claus
claus / migrar-mastodon.md
Created Jun 15, 2020
Migrando de uma instância Mastodon para outra
View migrar-mastodon.md

Migrando de uma instância para outra

Este é o passo-a-passo de como migrar sua conta no mastodon de uma instância para outra. Você pode migrar tudo (seguidores, seguidos, silenciados e bloqueados) exceto seus toots e mídia, você pode exportá-los mas não pode importá-los na nova instância.

Primeiro de tudo, para migrar de uma instância para outra, você deve fazer uma nova conta na instância para a qual você quer mudar, então siga os passos abaixo:

  1. Na nova instância vá em Preferências > Conta > Configurações da conta

    migrate-1

@claus
claus / _app.js
Created May 14, 2020
Restore scroll position after navigating via browser back/forward buttons in Next.js
View _app.js
import useScrollRestoration from "utils/hooks/useScrollRestoration";
const App = ({ Component, pageProps, router }) => {
useScrollRestoration(router);
return <Component {...pageProps} />;
};
export default App;
@claus
claus / flashforward.asm
Created Oct 16, 2019
6502 assembler intro for Flash Forward awards ceremony 2006 in Austin, Tx (FC64 emulator)
View flashforward.asm
; FC64 Flashforward Trailer
; =========================
; Basic: "1 SYS(2064)"
.a 0801
.b 0d,08,01,00,9e,28,32,30,36,34,29,00,00,00,00
@claus
claus / NextWorkboxPlugin.js
Last active Oct 15, 2019
Simple Webpack plugin to create Workbox based service workers for Next.js 9.1+ projects.
View NextWorkboxPlugin.js
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const readdir = require('recursive-readdir');
const SW_NAME = 'sw.js';
const fileBlacklist = [
'sw.js',
'build-manifest.json',
@claus
claus / screencapture.sh
Created Sep 11, 2018
MacOS: capture screenshot and add it to IPFS
View screencapture.sh
# Exit on errors
set -e
set -o pipefail
# Filename of captured image
FILE="$(date +%Y-%m-%d-%H-%M-%S).png"
# User/host
HOST="user@xx.xxx.xxx.xxx"
# Capture screen (interactively) and save image to the desktop
screencapture -i ~/Desktop/$FILE
# Upload the captured image to the server