Skip to content

Instantly share code, notes, and snippets.

@glw
glw / changefileext
Created February 11, 2015 07:04
change file extension
for file in *.JPG ; do mv $file `echo $file | sed 's/\(.*\.\)JPG/\1jpg/'` ; done
@glw
glw / gist:1b2e9e8b29b645bada84
Last active February 12, 2016 19:11
bash copy and move files and keep current modified date
cp -r -v -p <file> <dir>
@glw
glw / gist:6fc733c9beaaad462900
Last active August 29, 2015 14:18
shp2pgsql bulk import shpfiles
#Import a directory of shapefiles into postgis as a geometry
#replace EPSG SRID, database, and username, and others if necessary
for f in *.shp;
do
shp2pgsql -s <EPSG SRID> -g geom $f main.${f%.*} | psql -h localhost -p 5432 -d <database> -U <username>;
done
@glw
glw / gist:0e340a987acdc1a49814
Last active June 8, 2016 21:26
gdal compress and mosaic
#as seen on http://blog.cleverelephant.ca/2015/02/geotiff-compression-for-dummies.html
gdal_translate \
-co COMPRESS=JPEG \
-co PHOTOMETRIC=YCBCR \
-co TILED=YES \
5255C.tif 5255C_JPEG_YCBCR.tif
#create overviews
gdaladdo \
@glw
glw / geocoder
Last active October 21, 2015 22:19
python geocoder example
sudo pip install geocode
sudo apt-get install jq
sudo apt-get update
#from command line
#geocoder does not have to be google
#to save as json
geocode -p "google" addresses.txt | jq -r -c '@json' >> results3.json
#to save as csv
@glw
glw / map_drives
Created July 7, 2015 17:33
batch map network drives for Windows (dos)
:: repeat for all folders needed
:: replace anything between < > , as well as drive letter.
net use U: \\xx.xxx.xxx.xxx\folder <password> /user:<domain>\<username> /persistent:yes
@glw
glw / index.html
Last active August 29, 2015 14:26
Cross Domain GeoJSON w/ Omnivore and MapBoxJS
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<script src='https://api.mapbox.com/mapbox.js/v2.2.1/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v2.2.1/mapbox.css' rel='stylesheet' />
</head>
@glw
glw / environment
Created August 10, 2015 03:57
altered enviroment file to enable out of db and gdal drivers for postgis 2.1.x and below
# environment variables for postmaster process
# This file has the same syntax as postgresql.conf:
# VARIABLE = simple_value
# VARIABLE2 = 'any value!'
# I. e. you need to enclose any value which does not only consist of letters,
# numbers, and '-', '_', '.' in single quotes. Shell commands are not
# evaluated.
#====================================================
#Enable out of db rasters and gdal drivers
@glw
glw / scp-rsync
Last active June 17, 2016 22:44
use SCP or RSYNC to copy files from one computer to another
#for scp or rsync src and dest patterns are the same
scp /source/path/to/files [email protected]:/destination/pathh/to/files
#on Windows scp will work with Cygwin
##From local Windows machine to remote server. CD your way to the directory holding your file(s)
scp files.zip [email protected]:/home/projects
##From remote server to your local Windows machine. CD your way to the directory where you want to save your file
scp [email protected]:/home/projects/your_file.csv ./
@glw
glw / scheduleTask
Created February 25, 2016 22:56
schedule task via command line in Windows
#/create = create new task
#/tn = task name
#/sc = frequency
#/tr = command to start task
#more info https://technet.microsoft.com/en-us/library/cc772785%28WS.10%29.aspx#BKMK_create
schtasks /create /tn "createKML" /sc MONTHLY /tr "python c:\path\to\file.py"