Skip to content

Instantly share code, notes, and snippets.

View jczaplew's full-sized avatar

John J Czaplewski jczaplew

View GitHub Profile
@jczaplew
jczaplew / app.conf
Created November 21, 2014 17:45
Node + Apache
<VirtualHost *:80>
ServerName app.myurl.com
ProxyRequests off
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
@jczaplew
jczaplew / postgis2geojson.py
Last active March 23, 2023 19:08
A tool for extracting data from PostGIS into GeoJSON and TopoJSON. UPDATE: Added a dedicated repo for contributions - https://github.com/jczaplew/postgis2geojson
'''
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 / herok_github.md
Last active January 11, 2023 10:41
Heroku + Github + Sensitive Data

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 / pgFormatDate.js
Created April 24, 2015 14:11
Javascript Date to Postgres-acceptable format
// 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)
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
'''
Adapted from http://stackoverflow.com/a/1881201/1956065 and http://stackoverflow.com/a/25304159/1956065
12 January 2017
John J Czaplewski
john@czaplewski.org
'''
def xProduct(v0, v1, v2):
dx1 = v1[0] - v0[0]
dy1 = v1[1] - v0[1]
@jczaplew
jczaplew / real_example.sql
Last active September 29, 2021 08:24
Sample Along Line with PostGIS
SELECT ST_AsText(ST_LocateAlong(ST_AddMeasure(my_line, 0, ST_Length(my_line)::int), generate_series(0, ST_Length(my_line)::int))) FROM (
SELECT ST_GeomFromText('LINESTRING(-121 47, -80 26)') AS my_line
) q
@jczaplew
jczaplew / tqdm-multithreading.py
Last active September 22, 2021 16:43
tqdm with multithreading
from tqdm import *
from queue import Queue
from threading import Thread
import time
THREADS = 4
class WorkerThread(Thread):
def __init__(self, queue):
Thread.__init__(self)
@jczaplew
jczaplew / gist:5799404
Last active July 19, 2021 09:34
502 Proxy Error with Apache, Node, and MySQL
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 June 6, 2021 05:41
Setting up a LaunchDaemon with pm2

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