Skip to content

Instantly share code, notes, and snippets.

View suzukieng's full-sized avatar

Alex Suzuki suzukieng

View GitHub Profile
@suzukieng
suzukieng / cors-preflight-autoresponder.js
Created July 3, 2024 10:00
CORS Preflight Autoresponder CloudFront Function
/**
* CloudFront function for responding to CORS Preflight requests at the edge.
*
* See: https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request
*/
async function handler(event) {
const request = event.request;
if (request.method === 'OPTIONS' && request.headers.origin) {
// see: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/functions-event-structure.html#functions-event-structure-response
const response = {
@suzukieng
suzukieng / index.js
Created November 7, 2023 09:49
PDF417 sample code
// import STRICH SDK as an ES6 module directly from a CDN
import {StrichSDK, BarcodeReader} from 'https://cdn.jsdelivr.net/npm/@pixelverse/[email protected]/dist/strich.js';
// AAMVA helper routines
import {parseAAMVALicenseData} from "./aamva.js";
function processPDF417Barcode(codeDetection) {
// attempt to parse barcode data as AAMVA driver's license
const parsed = parseAAMVALicenseData(codeDetection.data);
@suzukieng
suzukieng / styles.css
Created November 7, 2023 08:45
PDF417 sample styles
body, html {
width: 100%;
font-family: sans-serif;
margin: 0;
}
.container {
height: 100vh;
position: relative;
background-color: black;
@suzukieng
suzukieng / index.html
Created November 7, 2023 08:43
PDF417 sample layout
<html lang="en">
<head>
<title>PDF417 Age Check</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
</head>
<body>
<div class="container">
<!-- this is where the barcode scanner will live -->
@suzukieng
suzukieng / index.html
Last active April 6, 2023 12:03
Schedule2 layout example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Schedule2</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="styles.css">
</head>
<body>
@suzukieng
suzukieng / bin.png
Last active December 21, 2022 14:50
Sample image where LSL implementation fails...
bin.png
@suzukieng
suzukieng / StateUpdate.kt
Last active December 10, 2021 13:08
StateUpdate.kt
private val uiState = mutableStateOf(UiState(/* initial state */))
// ...
override fun connectionLost(cause: Throwable?) {
uiState.value = uiState.value.copy(
statusMessage = "Connection lost",
connected = false
)
}
@suzukieng
suzukieng / UiState.kt
Created December 10, 2021 13:02
UiState.kt
/**
* Encapsulation of UI state
*/
data class UiState(
val connected: Boolean,
val statusMessage: String,
val window1Open: Boolean?,
val window2Open: Boolean?,
val window3Open: Boolean?,
val window4Open: Boolean?,
@suzukieng
suzukieng / sample.json
Created September 13, 2021 08:46
Proposed data format
{
"version": 1,
"metadata": {
"lastUpdated": "2021-09-13T08:41:16+0000",
"message": "Projektdaten Bahnhof Lausanne. Bei Fragen Mathias Kuhn kontaktieren."
},
"data": {
"documents": [
{
"number": "GC.GA.00.COF.DT.0001",
@suzukieng
suzukieng / JTouchID.java
Created August 25, 2021 13:29
JTouchID interface
package com.classycode.touchidexample;
import com.sun.jna.Callback;
import com.sun.jna.Library;
interface JTouchID extends Library {
interface AuthCallback extends Callback {
void callback(int result, int laError);