Skip to content

Instantly share code, notes, and snippets.

View Stanback's full-sized avatar

Brian Stanback Stanback

  • Demand.io
  • Los Angeles, California
View GitHub Profile
@Stanback
Stanback / nginx.conf
Last active February 4, 2022 18:05
Example Nginx configuration for serving pre-rendered HTML from Javascript pages/apps using the Prerender Service (https://github.com/collectiveip/prerender).Instead of using try_files (which can cause unnecessary overhead on busy servers), you could check $uri for specific file extensions and set $prerender appropriately.
# Note (November 2016):
# This config is rather outdated and left here for historical reasons, please refer to prerender.io for the latest setup information
# Serving static html to Googlebot is now considered bad practice as you should be using the escaped fragment crawling protocol
server {
listen 80;
listen [::]:80;
server_name yourserver.com;
root /path/to/your/htdocs;
@Stanback
Stanback / nginx.conf
Last active October 1, 2024 23:28 — forked from michiel/cors-nginx.conf
Example Nginx configuration for adding cross-origin resource sharing (CORS) support to reverse proxied APIs
#
# CORS header support
#
# One way to use this is by placing it into a file called "cors_support"
# under your Nginx configuration directory and placing the following
# statement inside your **location** block(s):
#
# include cors_support;
#
# As of Nginx 1.7.5, add_header supports an "always" parameter which
@Stanback
Stanback / api-rc.sh
Last active January 2, 2016 13:09
Example RC script that I've used for a Java/Scala/JVM service
#!/bin/bash
#
# This script provides start/stop/restart/status control
# over the JVM-based API service.
#
# Build Environment
BUILD_NAME="your-build-name"
BASE_DIR="/home/ubuntu/${BUILD_NAME}-deploy"
@Stanback
Stanback / phantom_test.js
Last active August 29, 2015 14:00
PhantomJS test of the XContentReady event
/*
* Simple test of PhantomJS and the XContentReady event.
*
* This is the basic pattern used for the ember-prerender project: https://github.com/zipfworks/ember-prerender
* More info on the XContentReady event: https://github.com/n-fuse/the-XContentReady-Event/
*
* Usage: phantomjs phantom_test.js
*/
var page = require('webpage').create();
@Stanback
Stanback / mongodb_curator.js
Created October 15, 2014 18:42
MongoDB Curator
//
// This script is useful for managing time series or log data
// that is stored in MongoDB.
//
// I'm currently using logstash to store system logs in MongoDB, where
// each database name denotes type of log and each collection name
// reflects the date on which the log entries it contains occurred.
//
// This script expects database collections to be in YYYY.MM.DD format.
//
@Stanback
Stanback / If-Modified-Since.php
Created October 27, 2014 17:19
Example of date-based browser caching
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= filemtime($path_to_image)) {
header('HTTP/1.0 304 Not Modified');
header('Cache-Control: public, max-age=2592000');
header('Last-Modified: Mon, 27 Oct 2014 17:08:41 GMT');
exit(0);
} else {
header('Content-type: image/jpeg');
header('Cache-Control: public, max-age=2592000');
header('Last-Modified: Mon, 27 Oct 2014 17:08:41 GMT');
echo file_get_contents($path_to_image);
@Stanback
Stanback / Dockerfile
Created March 28, 2015 01:21
PhantomJS 2.0 Dockerfile
#
# Example Dockerfile that builds PhantomJS 2.0
#
# Build with:
# docker build --rm --tag=phantom2.0:latest .
#
# Run with:
# docker run --name=phantom2.0 phantom2.0
#
# Copy the executable to your host machine for distribution:
#
# Oracle Java8 Dockerfile
#
FROM ubuntu
RUN apt-get update; \
apt-get install -y \
software-properties-common
@Stanback
Stanback / requestLogger.js
Last active November 18, 2015 17:32
Request logger middleware example using winston logger
// To use:
// server.use(requestLogger);
function requestLogger(req, res, next) {
req._startTime = new Date();
var logRequest = function() {
res.removeListener('finish', logRequest);
res.removeListener('close', logRequest);
var status = res.headersSent && res.statusCode || null;
var userAgent = req.headers['user-agent'];
@Stanback
Stanback / coffee2js.sh
Last active July 11, 2019 10:30
Convert all CoffeeScript files to Javascript (coffee2js)
#!/bin/sh
# Install coffeescript cli
npm -g install coffee-script
# Convert all coffeescript files to javascript
find . -name "*.coffee" -exec coffee --no-header --bare -c {} \;
# Optionally delete original coffee files
find . -name "*.coffee" -exec rm {} \;