Skip to content

Instantly share code, notes, and snippets.

@njbotkin
njbotkin / index.js
Last active July 13, 2020 15:04
Simple email relay built with node.js and mailgun
const addrs = require('email-addresses')
const RFC2821 = require('address-rfc2821')
const formBody = require('body/form')
const multiparty = require('multiparty')
const pify = require('pify')
const send = require('@polka/send-type')
/* global apiKey domain read send_email */
const mailgun = require('mailgun-js')({
@njbotkin
njbotkin / README.md
Last active December 19, 2019 13:25
Trigger SPA reloads without server polling with Cloudflare Workers

How it works:

  1. On app deploy, autoincrement Cloudflare KV value
  2. Cloudflare Worker adds a "version" cookie to every Response with the content from the KV
  3. Client checks cookies periodically to see if the "version" cookie has changed. If so, reload page
@njbotkin
njbotkin / client.js
Created August 31, 2019 21:34
Synchronous Stripe PaymentIntents Flow
export async function api(method, path = '', { body = {}, headers = {} } = {}) {
/* global ORIGIN */
let opts = { method, headers }
if(method == 'POST') {
opts.body = JSON.stringify(body)
}
let res = await fetch((process.browser ? '' : ORIGIN) + '/api/'+path, opts)
res.text = await res.text()
try {
res.json = JSON.parse(res.text)
@njbotkin
njbotkin / bootstrapwindows10.ps1
Last active May 9, 2019 05:37 — forked from zloeber/bootstrapwindows10.ps1
Boxstarter Windows 10 Configuration
<#
The command to run, built from the raw link of this gist
Win+R
iexplore http://boxstarter.org/package/url?<RAW GIST LINK>
OR (if you don't like the way the web launcher force re-installs everything)
# place in ~/.config/htop/htoprc
# Beware! This file is rewritten by htop when settings are changed in the interface.
# The parser is also very primitive, and not human-friendly.
fields=0 48 17 18 38 39 40 2 46 47 49 1
sort_key=46
sort_direction=1
hide_threads=0
hide_kernel_threads=0
hide_userland_threads=0
shadow_other_users=0
@njbotkin
njbotkin / DCC-bulk-download-bookmarklet.js
Last active January 25, 2018 04:46
Download DCC sermons in bulk
javascript:%22use%20strict%22;(function(){function%20e(e){var%20t=document.createElement(%22textarea%22);return%20t.innerHTML=e,t.value}var%20t=document.body.innerText.match(/%3Citem%3E[\s\S]*%3F%3C\/item%3E/g).reverse().reduce(function(t,c,n){var%20l=(%2200%22+(n+1)).slice(-3),a=e(c.match(/%3Ctitle%3E(%3F:[^%3C]+)%3F%3C\/title%3E/g).pop().slice(7,-8)),o=c.match(/%3Cenclosure%20url=%22([^%22]+)%22/).pop().replace(%22%26amp;%22,%22%26%22),i=new%20Date(c.match(/%3CpubDate%3E([^%3C]+)%3C\/pubDate%3E/g).pop().slice(9,-10)).toISOString().split(%22T%22)[0],r=l+%22_%22+i+%22_%22+a;return%20t+='%3Cdiv%3E%3Cinput%20type=%22checkbox%22%20checked%3E%26nbsp;%26nbsp;%3Ca%20href=%22'+o+'%22%20download=%22'+r+'.mp3%22%3E'+r+%22%3C/a%3E%3C/div%3E%22},%22%22),c=document.createElement(%22script%22);c.innerHTML='function%20setAll(bool)%20{Array.prototype.slice.call(document.getElementsByTagName(%22input%22)).forEach(e%20=%3E%20{e.checked%20=%20bool})}function%20clickAll()%20{Array.prototype.slice.call(document.getElementsByTagN
@njbotkin
njbotkin / runfile.js
Created January 9, 2018 20:12
sample runjs file
const { run } = require('runjs')
/* DATA */
function build_twine_data_to_decisions_html() {
run("node twine-parser/output-decisions-html-object.js")
}
function build_wordpress_data_to_svelte() {
run("node wordpress-parser/xml-to-svelte.js")