Skip to content

Instantly share code, notes, and snippets.

View jczaplew's full-sized avatar

John J Czaplewski jczaplew

View GitHub Profile
@jczaplew
jczaplew / array.map.js
Last active August 29, 2015 14:04
Array.map confusion
var data = [
{"name": null},
{"name": "a"},
{"name": "b"},
{"name": null},
{"name": null},
{"name": "c"}
];
var doesNotWork = data.map(function(d) {
@jczaplew
jczaplew / setup.md
Last active August 29, 2015 14:05
Set up Postgresql93 with Macports

Set up Postgresql93 with Macports

  1. sudo port install postgresql93-server
  2. sudo port select --set postgresql postgresql93
  3. sudo port load postgresql93-server
  4. sudo mkdir -p /opt/local/var/db/postgresql93/defaultdb
  5. sudo chown postgres:postgres /opt/local/var/db/postgresql93/defaultdb
  6. sudo su postgres -c '/opt/local/lib/postgresql93/bin/initdb -D /opt/local/var/db/postgresql93/defaultdb'
  7. Add to ~/.bash_profile...

Append to $PATH: /opt/local/lib/postgresql93/bin

@jczaplew
jczaplew / setup.md
Created August 7, 2014 20:05
Macports Postgres + PL/R

Macports Postgres + PL/R

  1. Install Postgres with Macports
  2. sudo port install pkgconfig
  3. sudo port install R
  4. download this http://www.joeconway.com/plr/plr-8.3.0.15.tar.gz
  5. uncompress it
  6. sudo mv /path/to/plr /opt/local/share/postgresql93/contrib
  7. cd /opt/local/share/postgresql93/contrib/plr
  8. R_HOME="/Library/Frameworks/R.framework/Resources" USE_PGXS=1 PG_CONFIG="/opt/local/lib/postgresql93/bin/pg_config" make
@jczaplew
jczaplew / add_11.py
Last active August 29, 2015 14:05
Add 11 hours to a directory of JPGs
# Back up your photos before running this!
import pyexiv2
import datetime
import glob
# Directory relative to where the script is -> change it to whatever you want
target_folder = "test"
hours_to_add = datetime.timedelta(hours=11)
time_keys = ["Exif.Image.DateTime", "Exif.Photo.DateTimeOriginal", "Exif.Photo.DateTimeDigitized"]
@jczaplew
jczaplew / count.js
Last active August 29, 2015 14:06
(Climbing) Suicide Counter
function countSuicide(moves) {
var totalMoves = 0;
for (var i = moves; i > 0; i--) {
totalMoves += i * 2;
}
return totalMoves;
}
@jczaplew
jczaplew / antarctica.sql
Created September 26, 2014 18:35
Sampling Problem
CREATE TABLE line_sample_test AS SELECT 1 AS id, ST_GeomFromGeoJSON('{ "type": "Polygon", "coordinates": [ [ [ -58.614142829001025, -64.152467130133232 ], [ -65.508424852140479, -67.581610209268831 ], [ -61.963369920485604, -74.439847920884802 ], [ -77.925858120419377, -78.378418884442254 ], [ -63.256030036050873, -81.748756605962484 ], [ -28.549802212018704, -80.337938327962092 ], [ -28.88277930349139, -76.673665059565636 ], [ -7.416621873392444, -71.696501159806132 ], [ 9.525134718472202, -70.011332702768129 ], [ 27.093726434037251, -70.462054545217882 ], [ 52.614132521378934, -66.053176371372132 ], [ 68.890038283162795, -67.934301859660906 ], [ 87.477017449903798, -66.876175232052503 ], [ 113.604673293107368, -65.876804707959906 ], [ 120.870999790532181, -67.18969614676729 ], [ 135.873804966373399, -66.033591003533502 ], [ 154.284567498999166, -68.561292012658186 ], [ 171.206790399457446, -71.696501159806132 ], [ 166.094802687848443, -74.381040140936705 ], [ 159.78821089094825, -80.945394789553049 ], [ 180
@jczaplew
jczaplew / ky_senate.geojson
Created October 10, 2014 20:20
Kentucky Senate Districts
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jczaplew
jczaplew / gist:08d9f7873fcc94fd1d71
Created October 13, 2014 18:12
Add/update git submodule
git submodule add https://github.com/your/repo presentations/destination_folder
git commit -m "Added submodule"
--make some changes--
cd presentations/destination_folder
git pull
@jczaplew
jczaplew / gist:3e40ce8675421ecd7a25
Last active August 29, 2015 14:07
Difference in area between projections
CREATE DATABASE ky;
CREATE EXTENSION postgis;
shp2pgsql -s 4326 senate_4326.shp | psql -h localhost -U john -d ky -p 5432
INSERT into spatial_ref_sys (srid, auth_name, auth_srid, proj4text, srtext) values ( 102680, 'ESRI', 102680, '+proj=lcc +lat_1=36.73333333333333 +lat_2=37.93333333333333 +lat_0=36.33333333333334 +lon_0=-85.75 +x_0=500000.0000000002 +y_0=500000.0000000002 +datum=NAD83 +units=us-ft +no_defs ', 'PROJCS["NAD_1983_StatePlane_Kentucky_South_FIPS_1602_Feet",GEOGCS["GCS_North_American_1983",DATUM["North_American_Datum_1983",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["False_Easting",1640416.666666667],PARAMETER["False_Northing",1640416.666666667],PARAMETER["Central_Meridian",-85.75],PARAMETER["Standard_Parallel_1",36.73333333333333],PARAMETER["Standard_Parallel_2",37.93333333333333],PARAMETER["Latitude_Of_Origin",36.33333333333334],UNIT["Foot_US",0.30480060960121924],AUTHORITY["EPSG","1