Skip to content

Instantly share code, notes, and snippets.

View bendytree's full-sized avatar

Josh Wright bendytree

View GitHub Profile
@bendytree
bendytree / noyito-relay.js
Created August 26, 2022 02:52
NOYITO USB Control Relay in NodeJS
const HID = require('node-hid');
class Relay {
constructor() {
const devices = HID.devices();
const deviceInfo = devices.find(d => d.product === 'USBRelay8');
this.device = new HID.HID(deviceInfo.path);
}
set(n, on) {
const send = Array(9).fill(0x0);
@bendytree
bendytree / s3hostfix.js
Created May 10, 2022 14:08
CloudFlare worker to rewrite Host header for S3
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
const lookup = {
"mybucket.example.com": "https://my-s3-bucket.s3.us-east-1.amazonaws.com",
};
async function handleRequest(origRequest) {
const origUrl = new URL(origRequest.url);
const fs = require('fs');
const _ = require('lodash');
const PNG = require('pngjs').PNG;
const { promisify } = require('util');
const md5File = require('md5-file');
const images = [
{ filename: 'graphic-gif.gif' },
{ filename: 'graphic-jpg-0.jpg' },
{ filename: 'graphic-jpg-76.jpg' },
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
import app from 'src/api';
import * as qs from 'query-string';
import axios from 'axios';
const settings = {
appId: '**************',
appSecret: '**************************',
redirectUrl: 'https://myapp.com/facebook/callback',
};
// https://joshwright.com/tips/google-authentication-for-nodejs/
import { google } from 'googleapis';
const buildAuth = function () {
return new google.auth.OAuth2(
'0000000000000-xxxxxxxx.apps.googleusercontent.com', // clientId
'XXXXXXXXXXXXXXXXXXX', // clientSecret
'http://localhost:7777/google/callback', // redirect
);
@bendytree
bendytree / component.vue
Created February 21, 2018 22:41
esModule option not working
<template>
<h1>Foo</h1>
</template>
@bendytree
bendytree / get-document-size.js
Created December 18, 2017 21:37
iOS iframe width workaround
/*
* This is a workaround for a bug on iOS which prevents iframes from
* knowing their size.
*
* When iframe calls `document.width`, the natural width of the content
* is returned instead of the iframe's width. So if the iframe is 360px
* wide and the body contains a 1024px image, then `document.width` will
* incorrectly return 1024.
*
* However, if the content is *smaller* than the iframe, then the correct
@bendytree
bendytree / WKWebViewPanelManager.h
Created November 4, 2015 20:10
Easily show WKWebView alerts, prompts, and confirms
//
// WKWebViewPanelManager.h
//
// A few helpers to easily show WKWebView alerts, confirms, and prompts.
//
// Created by Joshua Wright<@bendytree> on 11/4/15.
//
// License: MIT
//
// Inspired by: https://github.com/ShingoFukuyama/WKWebViewTips
@bendytree
bendytree / nginx.conf.template
Created October 22, 2015 20:11
NGINX Config template for Dokku
server {
listen [::]:80;
listen 80;
server_name $NOSSL_SERVER_NAME;
location / {
proxy_pass http://$APP;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";