Skip to content

Instantly share code, notes, and snippets.

View claus's full-sized avatar
🎅

Claus Wahlers claus

🎅
View GitHub Profile
@claus
claus / base64fixer.js
Created August 25, 2021 19:12
Fixes base64 casing in case it got lost
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);
@claus
claus / gist:940219
Created April 25, 2011 06:04
as3potrace demo
package
{
import com.bit101.components.CheckBox;
import com.bit101.components.ComboBox;
import com.bit101.components.PushButton;
import com.powerflasher.as3potrace.POTrace;
import com.powerflasher.as3potrace.backend.GraphicsDataBackend;
import flash.display.Bitmap;
import flash.display.BitmapData;
/*
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.

A while ago i needed a way to look up addresses from zip codes in Brazil for a weekend tinker project (Zip codes are called "CEP" here, "Código de Endereçamento Postal", or Postal Addressing Code). Turns out such a database is pretty hard to get hold of. Zip code data is created and maintained by the Brazilian Post (Correios), they have a copyright on it and are selling it for a hefty price tag. There are two versions for sale, "DNE Básico" for R$1.100 (complete dataset in text format, probably CSV), and "DNE Máster" for R$2.500. As far as i aware, the "Máster" version is just the same as the "Básico" version, but additionally contains the database in MS Access format. Okay, both are a bit above my budget.

Luckily there is another option, called "Guia Postal Brasileiro Eletrônico", or GPBe. This is an executable that you can run on your PC to manually query zip codes and addresses. And to be able to do that it must somehow contain the entire database in some form. It costs R$50, which is affordable (about US

@claus
claus / example.js
Last active January 24, 2021 08:30
Proxy wrapper for tweenjs that automatically starts/stops requestAnimationFrame so you don't have to
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)
// Author: Claus Wahlers
// License: Public Domain
// Dependencies:
// as3commons-bytecode-1.0-RC1.swc
// as3commons-lang-0.3.2.swc
// as3commons-logging-2.0.swc
// as3commons-reflect-1.3.4.swc
// as3swf.swc
// MinimalComps_0_9_9.swc
@claus
claus / PNGPacker.as
Created June 8, 2011 18:04
Create SWF with PNGs
package
{
// Dependencies:
// as3swf.swc
// as3commons-bytecode-1.0-RC1.swc
// as3commons-lang-0.3.2.swc
// as3commons-logging-2.0.swc
// as3commons-reflect-1.3.4.swc
// MinimalComps_0_9_9.swc
@claus
claus / sbRichTextReactRenderer.js
Last active August 1, 2020 06:43
Storyblok Rich Text Renderer for React
/*
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
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 June 15, 2020 23:50
Migrando de uma instância Mastodon para outra

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