Skip to content

Instantly share code, notes, and snippets.

View antony's full-sized avatar
:octocat:
Loving SvelteJS

Antony Jones antony

:octocat:
Loving SvelteJS
View GitHub Profile
@antony
antony / fix-vercel.sh
Last active October 16, 2023 18:43
WASM dependency on Vercel
#!/bin/bash
VERCEL_OUTPUT_DIR=.vercel_build_output
LAMBDA_DIR=.vercel_build_output/functions/node/render/
cp -r static $LAMBDA_DIR/static
cp node_modules/sharp/build/Release/*.node $LAMBDA_DIR
cp node_modules/canvas/build/Release/*.node $LAMBDA_DIR
cp node_modules/sharp/vendor/8.11.3/linux-x64/lib/libvips-cpp.so.42 $LAMBDA_DIR
cp ./images.json $VERCEL_OUTPUT_DIR
sed -i 's#\.\./build/Release#\.#g' $LAMBDA_DIR/index.js
@antony
antony / SimpleFileUploader.svelte
Created September 18, 2019 16:03
File Uploader Svelte
<label>
{#if uploading}
<Progress bind:percent={progress} text="Uploading..." />
{:else if processing}
<Progress percent={100} text="Processing..." />
{:else}
<slot name="content">
</slot>
{/if}
<input
@antony
antony / deploy.sh
Last active September 7, 2023 09:01
Deploying Sapper to Vercel using Build Output v3 API
pnpm run build
cd __sapper__/build/
mkdir -p $PUBLIC_DIR/${{ inputs.base_path }}
mv client $PUBLIC_DIR/${{ inputs.base_path }}
cp -r ../../static/* $PUBLIC_DIR/
mkdir -p $LAMBDA_DIR
mv index.js server $LAMBDA_DIR/
mkdir -p $BUILD_DIR
mv service-worker.js template.html build.json $BUILD_DIR
cp ${{ github.workspace }}/vercel.json ./app/
@antony
antony / process.env.robotsTxt
Created October 22, 2018 09:26
Simple robots.txt generation for Sapper
{
UserAgent: '*',
Disallow: '/'
}
@antony
antony / convert.js
Created June 6, 2023 15:00
Convert from node-config to dotenv. Thanks ChatGPT!
'use strict'
const fs = require('fs')
const path = require('path')
const dotenv = require('dotenv')
const configDirPath = path.join(__dirname, './config')
const outputDirPath = path.join(__dirname, '.')
const toUpperSnakeCase = (str) => str.replace(/([a-z])([A-Z])/g, '$1_$2').toUpperCase()
@antony
antony / bash.sh
Last active February 8, 2022 01:36
Auth0 SSR Compatible Integration with Sapper
npm install --save express express-openid-connect
From: https://stackoverflow.com/questions/23150333/html5-javascript-dataurl-to-blob-blob-to-dataurl
//**dataURL to blob**
function dataURLtoBlob(dataurl) {
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], {type:mime});
@antony
antony / index.js
Last active January 16, 2022 16:35
A very quick authentication server which validates a JWT
'use strict'
require = require('esm')(module)
const { init, shutdown } = require('./server.js')
async function bootstrap () {
const server = await init()
await server.start()
console.log(`Server running at: ${server.info.uri}`)
}
@antony
antony / Flipper.svelte
Created August 10, 2019 08:45
An example of a div which can flip its content
<div class="card-container">
<div class="card">
{#if flipped}
<div class="side" transition:turn>
<slot name="front"></slot>
</div>
{:else}
<div class="side back" transition:turn>
<slot name="back"></slot>
</div>
@antony
antony / build.js
Last active March 11, 2021 01:45
custom-feather-icons
const feather = require('feather-icons/dist/icons.json')
const pascal = require('just-pascal-case')
const { promises: fs } = require('fs')
const { join } = require('path')
const iconList = require('./icon-list.json')
const handleComponentName = name => name.replace(/\-(\d+)/, '$1')
const component = icon =>
`<script>