Skip to content

Instantly share code, notes, and snippets.

Tate Thurston tatethurston

Block or report user

Report or block tatethurston

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tatethurston
tatethurston / SimpleAuthServer.py
Created Mar 14, 2018 — forked from fxsjy/SimpleAuthServer.py
SimpleAuthServer: A SimpleHTTPServer with authentication
View SimpleAuthServer.py
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
import sys
import base64
key = ""
class AuthHandler(SimpleHTTPRequestHandler):
''' Main class to present webpages and authentication. '''
def do_HEAD(self):
@tatethurston
tatethurston / index.js
Last active Dec 29, 2017
node multiprocess
View index.js
import * as throng from 'throng';
const { WEB_CONCURRENCY = 1, PORT = "" } = process.env;
const start = async (id: number) => {
/*
* This could be imported statically at the top, but then the master process
* could be crashed.
*/
const server = require('./server').default;
@tatethurston
tatethurston / docker-compose.yml
Last active Nov 19, 2017
rails docker compose
View docker-compose.yml
version: '3'
services:
db:
image: postgres
# ports:
# - "5432:5432"
web:
image: ruby:2.3-onbuild
command: bundle exec rails s -p 5000 -b '0.0.0.0'
@tatethurston
tatethurston / poll.js
Created Nov 14, 2017
JavaScript polling
View poll.js
// fn: () => Promise<Boolean>
const poll = (fn, interval = 100, maxWait = 60000) => {
const start = Date.now();
let last = 0;
return new Promise((resolve, reject) => {
const _poll = () => {
const now = Date.now();
console.log(start, last, now, interval);
if (now > start + maxWait) {
@tatethurston
tatethurston / deploy-to-s3.js
Last active Nov 19, 2017
node script for AWS S3 uploads
View deploy-to-s3.js
/*
* NOTE: You'll need to follow the steps outlined in aws-config.js.example
* before running this deploy script for the first time
*/
// https://github.com/andrewrk/node-s3-client
const s3 = require('s3');
const DIRECTORY = 'dist';
@tatethurston
tatethurston / webpack.config.js
Created Nov 12, 2017
Webpack config with HMR + deterministic content hashing
View webpack.config.js
const _ = require('lodash');
const isDev = process.env.NODE_ENV !== 'production'
const APP_PATH = '';
const BUILD_PATH = '';
const config = {
// Fail early
bail: true,
View rails-api-setup.sh
NAME=''
rails new $NAME \
--api \
--database=postgresql \
--skip-action-cable
cd $NAME
rm -rf \
View heroku-deploy.sh
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
post_slack() {
SLACK_URL="TODO:_FILL_ME_IN"
curl -X POST \
-H "Content-Type: application/json" \
-d "{\"text\": \"$1\"}" \
@tatethurston
tatethurston / .eslintrc.js
Last active Nov 23, 2017
.eslintrc import/no-unresolved NODE_PATH
View .eslintrc.js
module.exports = {
"extends": "eslint:recommended",
"env": {
"node": true,
"mocha": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 8
},
@tatethurston
tatethurston / ajax.js
Created Jun 28, 2017
Retry jQuery AJAX requests with exponential backoff
View ajax.js
import $ from 'jquery';
import uuidv4 from 'uuid/v4';
const wait = ms => $.Deferred(defer => setTimeout(defer.resolve, ms));
const request = (opts, numTries = 0) => {
/*
* Retry failed requests 2 additional times with exponential backoff
*/
const RETRY_COUNT = 2;
You can’t perform that action at this time.