Skip to content

Instantly share code, notes, and snippets.

View richard-flosi's full-sized avatar

Richard Flosi richard-flosi

  • Remote, US
View GitHub Profile
@richard-flosi
richard-flosi / star-wars-planets.html
Last active January 17, 2024 07:58
Web Component using Custom Element, Shadow DOM, fetch, async/await, and the Star Wars API
<html>
<head>
<script>
customElements.define("star-wars-planets", class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
}
static get observedAttributes() { return ["loading", "planets"]; }
@richard-flosi
richard-flosi / bottle-cors.py
Created September 26, 2012 16:55
Bottle with Cross-origin resource sharing (CORS)
"""
Example of setting up CORS with Bottle.py.
"""
from bottle import Bottle, request, response, run
app = Bottle()
@app.hook('after_request')
def enable_cors():
"""
@richard-flosi
richard-flosi / flutter-netlify-build.sh
Last active July 1, 2023 21:15
Netlify Build command script to deploy a Flutter Web App
#!/bin/sh
FLUTTER_BRANCH=`grep channel: .metadata | sed 's/ channel: //g'`
FLUTTER_REVISION=`grep revision: .metadata | sed 's/ revision: //g'`
git clone https://github.com/flutter/flutter.git
cd flutter
git checkout $FLUTTER_BRANCH
git pull origin $FLUTTER_BRANCH
git checkout $FLUTTER_REVISION
cd ..
@richard-flosi
richard-flosi / build.sh
Created July 14, 2020 00:08
Build Script to Deploy Flutter Web app on Netlify
#!/bin/bash
# Get flutter
git clone https://github.com/flutter/flutter.git
FLUTTER=flutter/bin/flutter
# Configure flutter
FLUTTER_CHANNEL=master
FLUTTER_VERSION=v1.17.0
$FLUTTER channel $FLUTTER_CHANNEL
@richard-flosi
richard-flosi / assertions-compareScreenshot.js
Created August 27, 2014 14:25
Nightwatch with Visual Regression testing
// assertions/compareScreenshot.js
var resemble = require('resemble'),
fs = require('fs');
exports.assertion = function(filename, expected) {
var screenshotPath = 'test/screenshots/',
baselinePath = screenshotPath + 'baseline/' + filename,
resultPath = screenshotPath + 'results/' + filename,
diffPath = screenshotPath + 'diffs/' + filename;
@richard-flosi
richard-flosi / async-generator.js
Created February 23, 2022 21:49
Example of *yield to pass proxy to another function compared to awaiting each next() value and applying a transformation before yielding
// When you just need to pass through the value yield from another generator function use:
yield* generatorFunction();
// When you need to manipulate each yielded value
const generator = generatorFunction();
let next = await generator.next();
while (!next.done) {
let value = next.value;
// TODO apply any transformations to value here
yield value;
@richard-flosi
richard-flosi / trilateration.js
Last active April 12, 2021 04:09
JavaScript Trilateration
// Created by Derrick Cohodas (dav-)
// Based on the Python example by StackExchange user wwnick from http://gis.stackexchange.com/a/415/41129
// Requires the Mathjs library - http://mathjs.org/
var math = require('mathjs')
/**
* Represents a coordinate with a distance
* @param {Number} lat Latitude
@richard-flosi
richard-flosi / operations.js
Created April 27, 2020 19:49
serverless express-openapi over netlify functions
const usersApi = require("./users");
module.exports = {
// /users
"post-users": usersApi.post,
"get-users": usersApi.get,
// /users/{userId}
"get-users-userId": usersApi.get,
"patch-users-userId": usersApi.patch,
"delete-users-userId": usersApi.delete,
@richard-flosi
richard-flosi / app.js
Created April 9, 2014 18:02
Spine App example with navigation method
module.exports = (function() {
var App,
Spine = require('spine'),
$ = Spine.$;
// extend Spine
require('spine/lib/local');
require('spine/lib/ajax');
require('spine/lib/route');
require('spine/lib/manager');
@richard-flosi
richard-flosi / slug.js
Created April 9, 2014 17:59
Hem precompiler for nunjucks templates
/* jshint node: true */
var argv = process.argv.slice(2);
var fs = require('fs');
var hem = new (require('hem'))();
hem.compilers.html = function(path) {
var nunjucks = require('nunjucks'),
name = path.split('app/')[1],
opts = {
name: name,