Skip to content

Instantly share code, notes, and snippets.

View loganpowell's full-sized avatar

Logan Powell loganpowell

  • Metro DC
View GitHub Profile
@loganpowell
loganpowell / jsdom-prerender.js
Created April 27, 2023 12:49 — forked from lovetingyuan/jsdom-prerender.js
use jsdom to prerender simple page.
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const path = require('path')
const fetch = require('node-fetch')
const finalhandler = require('finalhandler')
const http = require('http')
const serveStatic = require('serve-static')
function createServer (port, root = path.join(__dirname, 'dist')) {
const serve = serveStatic(root)
@loganpowell
loganpowell / summary_level_dict
Created April 6, 2021 15:24 — forked from ryanpitts/summary_level_dict
Summary level codes for Census and ACS
# Sources:
# http://mcdc2.missouri.edu/pub/data/sf32000/Techdoc/ch4_summary_level_seq_chart.pdf
# http://www2.census.gov/acs2011_1yr/summaryfile/ACS_2011_SF_Tech_Doc.pdf
SUMMARY_LEVEL_DICT = {
"010","United States",
"020","Region",
"030","Division",
"040","State",
"050","State-County",
"060","State-County-County Subdivision",

How to setup AWS lambda function to talk to the internet and VPC

I'm going to walk you through the steps for setting up a AWS Lambda to talk to the internet and a VPC. Let's dive in.

So it might be really unintuitive at first but lambda functions have three states.

  1. No VPC, where it can talk openly to the web, but can't talk to any of your AWS services.
  2. VPC, the default setting where the lambda function can talk to your AWS services but can't talk to the web.
  3. VPC with NAT, The best of both worlds, AWS services and web.
@loganpowell
loganpowell / cors.js
Created March 30, 2020 14:03 — forked from balupton/cors.js
Acheiving CORS via a Node HTTP Server
// Create our server
var server;
server = http.createServer(function(req,res){
// Set CORS headers
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Request-Method', '*');
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
res.setHeader('Access-Control-Allow-Headers', '*');
if ( req.method === 'OPTIONS' ) {
res.writeHead(200);
@loganpowell
loganpowell / redis_streams_w_ioredis.js
Created March 27, 2020 19:49 — forked from forkfork/ioredis_example.js
Example of using Redis Streams with Javascript/ioredis
var Redis = require('ioredis');
var redis = new Redis({
host: "nodesydney.wiftycloud.com",
password: "7884b8baaa49fbcb48f17ad2a146"
});
async function main() {
// write an event to stream 'events', setting 'key1' to 'value1'
await redis.sendCommand(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Content-Security-Policy</title>
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' data: gap: 'unsafe-eval' ws: ;
style-src 'self' 'unsafe-inline';
script-src https: *.example.com ;
@loganpowell
loganpowell / package.json
Created January 20, 2020 00:11 — forked from adamreisnz/package.json
Simple pure npm scripts build process
{
"name": "project-name",
"description": "Template for static sites",
"version": "1.0.0",
"homepage": "http://www.project-name.com",
"author": {
"name": "Adam Reis",
"url": "http://adam.reis.nz"
},
"license": "UNLICENSED",
@loganpowell
loganpowell / tail-call-optimization-hack.js
Last active October 4, 2019 14:18 — forked from Gozala/example.js
Workaround for lack of "tail call optimization" in JS
// Lack of tail call optimization in JS
var sum = function(x, y) {
return y > 0 ? sum(x + 1, y - 1) :
y < 0 ? sum(x - 1, y + 1) :
x
}
sum(20, 100000) // => RangeError: Maximum call stack size exceeded
// Using workaround
@loganpowell
loganpowell / index.html
Created September 6, 2019 14:18 — forked from nolanlawson/index.html
Web Worker via blob URL
<!doctype html>
<html lang="en">
<body>
<span id="output"></span>
</body>
<script>
(function () {
var workerBlob = new Blob(
[workerRunner.toString().replace(/^function .+\{?|\}$/g, '')],
{ type:'text/javascript' }
@loganpowell
loganpowell / aws-couchdb-setup.md
Created August 18, 2019 09:50 — forked from Ravenstine/aws-couchdb-setup.md
Fast CouchDB setup in AWS

Fast CouchDB setup in AWS

CouchDB is a NoSQL database for storing JSON documents. It comes with a REST API out of the box so your client applications can persist data while requiring you to write little or no server-side code. CouchDB's killer feature is its ability to easily replicate, which allows for horizontal scaling, easy backup, and for client adapters to synchronize documents. This is perfect if you want to write an application that is offline-first. It's become my go-to database when creating new