Skip to content

Instantly share code, notes, and snippets.

Avatar

John J Czaplewski jczaplew

View GitHub Profile
@jczaplew
jczaplew / gist:5799404
Last active Jul 19, 2021
502 Proxy Error with Apache, Node, and MySQL
View gist:5799404
Setup:
Node running on :8080
Apache running on :80
Using Apache mod_proxy to forward application requests to :8080
Symptoms
On client:
1. Proxy Error
The proxy server received an invalid response from an upstream server.
@jczaplew
jczaplew / README.md
Last active Jun 6, 2021
Setting up a LaunchDaemon with pm2
View README.md

Setting up a LaunchDaemon with pm2

If you have a Node.js app running on an OS X server, you probably:

  • Want it to start automatically when the system boots
  • Want to use something like pm2 or forever to monitor the status of the app, log errors, and make sure it stays up

While pm2 has the ability to generate startup scripts for use with Ubunutu, Centos, and systemd, it does not work with OS X. The best approach is to use launchd, an OS X-specific daemon manager that replaces cron. It uses XML-based files for configuration. This guide will walk you through the process. Note: "xyz" is used as a placeholder for the application name throughout this guide.

Instructions

@jczaplew
jczaplew / postgis2geojson.py
Last active Apr 5, 2021
A tool for extracting data from PostGIS into GeoJSON and TopoJSON. UPDATE: Added a dedicated repo for contributions - https://github.com/jczaplew/postgis2geojson
View postgis2geojson.py
'''
A simple tool for exporting from a PostGIS table to GeoJSON and TopoJSON. Assumes Python 2.7+,
psycopg2, and TopoJSON are already installed and in your PATH.
Adapted from Bryan McBride's PHP implementation
(https://gist.github.com/bmcbride/1913855/)
by John Czaplewski | jczaplew@gmail.com | @JJCzaplewski
TODO:
- Add argument for SRS
@jczaplew
jczaplew / pgFormatDate.js
Created Apr 24, 2015
Javascript Date to Postgres-acceptable format
View pgFormatDate.js
// Convert Javascript date to Pg YYYY MM DD HH MI SS
function pgFormatDate(date) {
/* Via http://stackoverflow.com/questions/3605214/javascript-add-leading-zeroes-to-date */
function zeroPad(d) {
return ("0" + d).slice(-2)
}
var parsed = new Date(date)
@jczaplew
jczaplew / readme.md
Created Feb 4, 2014
PostGIS to MySQL
View readme.md

Postgres:

psql

   CREATE DATABASE federal lands; 
   \c federal lands;
   CREATE EXTENSION postgis;
   CREATE EXTENSION postgis_topology;

shell

shp2pgsql -s 4326 fedlanp020.shp | psql -h localhost -U john -d federal_lands

View github-print-bookmarklet
javascript:(function(e,a,g,h,f,c,b,d)%7Bif(!(f=e.jQuery)%7C%7Cg%3Ef.fn.jquery%7C%7Ch(f))%7Bc=a.createElement(%22script%22);c.type=%22text/javascript%22;c.src=%22http://ajax.googleapis.com/ajax/libs/jquery/%22+g+%22/jquery.min.js%22;c.onload=c.onreadystatechange=function()%7Bif(!b&&(!(d=this.readyState)%7C%7Cd==%22loaded%22%7C%7Cd==%22complete%22))%7Bh((f=e.jQuery).noConflict(1),b=1);f(c).remove()%7D%7D;a.documentElement.childNodes%5B0%5D.appendChild(c)%7D%7D)(window,document,%221.3.2%22,function($,L)%7B$('%23header,%20.pagehead,%20.breadcrumb,%20.commit,%20.meta,%20%23footer,%20%23footer-push,%20.wiki-actions,%20%23last-edit,%20.actions,%20.header,.site-footer,.repository-sidebar,.file-navigation,.gh-header-meta,.gh-header-actions,#wiki-rightbar,#wiki-footer,.commit-tease').remove();%20$('%23files,%20.file').css(%7B%22background%22:%22none%22,%20%22border%22:%22none%22%7D);%20$('link').removeAttr('media');%7D); var removeMe = document.getElementsByClassName("file-header")[0]; removeMe.parentNode.removeChild(r
@jczaplew
jczaplew / herok_github.md
Last active Jan 22, 2021
Heroku + Github + Sensitive Data
View herok_github.md

Heroku + Github + Sensitive Data

Scenario: You deployed a Heroku project that contains sensitive data (password, API key, etc) but you want to share it on Github.

Problem: You need to commit all files necessary for the application to run on Heroku. However, pushing this to Github would reveal the sensitive info.

Solution: Have a production branch (for this example, master will be the production branch) and a Github branch. The latter contains a different .gitignore that ignores the sensitive files.

@jczaplew
jczaplew / README.md
Last active Jan 18, 2021
Geologic Time Scale
View README.md
@jczaplew
jczaplew / index.html
Created Aug 24, 2017
Supercluser + tilestrata + Mapbox GL JS
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
@jczaplew
jczaplew / import_csv.py
Created Nov 28, 2016
Auto import csv to Postgres
View import_csv.py
import csv
import sys
import subprocess
with open(sys.argv[1], 'rb') as csvfile:
reader = csv.reader(csvfile)
header_row = reader.next()
cmd1 = "psql -U you dbname -c 'CREATE TABLE " + sys.argv[2] + " ("
for idx, column in enumerate(header_row):