Skip to content

Instantly share code, notes, and snippets.

@fgnass
fgnass / README.md
Created October 19, 2020 14:04
Next.js SSR + Capacitor

Goal

The goal is to package a server-side rendered Next.js app as SPA for capacitor.

Approach

Pages with dynamic routes/data use getServerSideProps(). For capacitor we need at least one page that can be rendered statically, preferably the index page.

When there are pages that use getServerSiedeProps() we can't use next export (it will fail with an error).

@fgnass
fgnass / keybase.md
Created August 23, 2020 12:22
keybase.md

Keybase proof

I hereby claim:

  • I am fgnass on github.
  • I am fgnass (https://keybase.io/fgnass) on keybase.
  • I have a public key ASBTra-cTg-Ff-R-1_WL1vyGiYM8zCgf9oBm5lSqUqM1iQo

To claim this, I am signing this object:

r = readline;
[...Array(+r())]
.map(r)
.map(l => /(.+): (.+) /.exec(l))
.map(
([, n, c]) =>
(c.split("-").map(c => 117 - c.charCodeAt(0)) + "").padEnd(20, ",1") + n
)
.sort()
.map(e => writeline(e.slice(20)));
@fgnass
fgnass / microbit.ts
Created August 18, 2018 13:48
Microbit Game
let ball: game.LedSprite = null
let player: game.LedSprite = null
let score = 0
let lives = 0
input.onButtonPressed(Button.A, () => {
player.move(-1)
})
input.onButtonPressed(Button.B, () => {
player.move(1)
})
@fgnass
fgnass / convert.sh
Created May 31, 2018 14:19
Convert wav into mp3 files suitable for Alexa and Google Actions
#!/bin/bash
set -e
# Rename files to make them URL friendly
# https://formulae.brew.sh/formula/slugify
slugify *
# Trim silence at the beginning
@fgnass
fgnass / history.js
Last active May 7, 2018 10:03
Use arrow keys to scroll through the input history in Amazon's Alexa simulator
(function() {
let i = 0;
const el = document.querySelector('.askt-utterance__input');
el.addEventListener('keyup', function(ev) {
const req = document.querySelectorAll('.askt-dialog__message--request');
if (ev.key == 'ArrowUp') i = i >= req.length - 1 ? 0 : i + 1;
else if (ev.key == 'ArrowDown') i = i > 0 ? i - 1 : req.length - 1;
else return;
el.value = '';
document.execCommand('insertText', false, req[i].innerText);
@fgnass
fgnass / replay.js
Created May 4, 2018 08:58
Re-submit Alexa requests by clicking on previous inputs
// Paste this into your borwser's console on the Alexa Skill testing page:
document.addEventListener('click', ev => {
if (ev.target.matches('.askt-dialog__message--request')) {
const el = document.querySelector('.askt-utterance__input');
el.focus();
document.execCommand('insertText', false, ev.target.innerText);
el.dispatchEvent(
new KeyboardEvent('keypress', { bubbles: true, keyCode: 13 })
);
@fgnass
fgnass / index.js
Created July 20, 2017 20:50
React E2E testing in Headless Chrome with unexpected.js and retractor
import webdriver from 'friendly-webdriver';
import unexpected from 'unexpected';
import unexpectedWebdriver from 'unexpected-webdriver';
import retractor from 'retractor';
const expect = unexpected.clone();
expect.use(unexpectedWebdriver());
/* @jsx retractor */
@fgnass
fgnass / index.js
Last active April 20, 2017 07:07
<💅> primary, secondary, :hover
import styled, { css } from 'styled-components';
const Button = styled.button`
font-size: 1em;
margin: 1em;
border: 2px solid palevioletred;
border-radius: 3px;
color: palevioletred;
${props => props.primary && css`
@fgnass
fgnass / styled-components.js
Last active April 20, 2017 07:03
Pattern for styled components with lots of states
import styled, { css } from 'styled-components';
const Button = styled.button`
font-size: 1em;
margin: 1em;
border: 2px solid palevioletred;
border-radius: 3px;