Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh Wright bendytree

View GitHub Profile
@bendytree
bendytree / s3hostfix.js
Created May 10, 2022
CloudFlare worker to rewrite Host header for S3
View s3hostfix.js
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);
View instagram-compression-analysis.js
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' },
View s3-cors.xml
<?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>
View facebook-auth-routes.js
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',
};
View google-routes.js
// 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 Feb 21, 2018
esModule option not working
View component.vue
<template>
<h1>Foo</h1>
</template>
@bendytree
bendytree / get-document-size.js
Created Dec 18, 2017
iOS iframe width workaround
View get-document-size.js
/*
* 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 Nov 4, 2015
Easily show WKWebView alerts, prompts, and confirms
View WKWebViewPanelManager.h
//
// 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 Oct 22, 2015
NGINX Config template for Dokku
View nginx.conf.template
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";
View gist:615960cc9cb583d75cac
var async = require('async');
var https = require('https');
async.times(5, function(n, cb){
var options = { host: 'www.google.com', port: 443, path: '', method: 'GET' };
var startTime = new Date().getTime();
var req = https.request(options, function(res) {
var ms = new Date().getTime() - startTime;
console.log(ms+"ms");
res.on('data', function(){ });