Skip to content

Instantly share code, notes, and snippets.

View AndrewTheTM's full-sized avatar
🏃‍♂️

Andrew Rohne AndrewTheTM

🏃‍♂️
View GitHub Profile
@AndrewTheTM
AndrewTheTM / getCensusJSON.py
Created July 16, 2012 14:13
Read Census Data via Python
import json,urllib,cairoplot
url='http://thedataweb.rm.census.gov/data/2010/sf1?key={YOUR_KEY_HERE}&get=P0010001,NAME&for=county:025,017,061,165&in=state:39'
result=json.load(urllib.urlopen(url))
graphData=[]
graphLabels=[]
for row in result:
@AndrewTheTM
AndrewTheTM / CubeScriptWriteScript
Created October 4, 2012 18:09
Cube Script to Write Script
RUN PGM=MATRIX
FILEO PRINTO="WrittenScript.S"
PAR ZONES=1
PRINT PRINTO=1 LIST="RUN PGM=MATRIX"
PRINT PRINTO=1 LIST="FILEO RECO=\"INPUT\DATABASE.DBF\" FIELDS="
LOOP i=1,30
_yr=2010+i
@AndrewTheTM
AndrewTheTM / VoyagerDLLInterface
Created October 5, 2012 13:31
Voyager DLL Interface Java
public interface voyagerDLL extends Library{
voyagerDLL INSTANCE=(voyagerDLL) Native.loadLibrary("VoyagerFileAccess",voyagerDLL.class);
Pointer MatReaderOpen(String filename, Pointer errMsg, int errBuffLen);
int MatReaderGetNumMats(Pointer state);
int MatReaderGetNumZones(Pointer state);
int MatReaderGetMatrixNames(Pointer state, String[] names);
int MatReaderGetRow(Pointer state, int MatNumber, int RowNumber, double[] buffer);
void MatReaderClose(Pointer state);
}
@AndrewTheTM
AndrewTheTM / VoyagerDLLvoidmain
Created October 5, 2012 13:59
Voyager DLL main class Java
public static void main(String[] args) {
try{
voyagerDLL vdll=voyagerDLL.INSTANCE;
String err="";
int errB=256;
Pointer state=vdll.MatReaderOpen("C:\\Modelrun\\05e05i05i05aV76_Validation\\VEHTRPAM.MAT", err, errB);
int nMats=vdll.MatReaderGetNumMats(state);
int Zones=vdll.MatReaderGetNumZones(state);
String[] matNames=new String[nMats];
int names=vdll.MatReaderGetMatrixNames(state, matNames);
@AndrewTheTM
AndrewTheTM / prDllInterface
Created October 8, 2012 12:42
Path Reader DLL Interface
public interface voyagerDLL extends Library{
voyagerDLL INSTANCE=(voyagerDLL) Native.loadLibrary("VoyagerFileAccess",voyagerDLL.class);
Pointer PathReaderOpen(String filename, String errMsg, int errBL);
void PathReaderClose(Pointer state);
int PathReaderGetTableNames(Pointer state, String[] names);
int PathReaderGetNumZones(Pointer state);
int PathReaderGetNumTables(Pointer state);
int PathReaderGetNumIterations(Pointer state);
int PathReaderGetHighestVol(Pointer state);
int PathReaderGetMaxPathLen(Pointer state);
@AndrewTheTM
AndrewTheTM / prDllProgram
Created October 8, 2012 13:31
Path Reader DLL Program
public static void main(String[] args) {
try{
voyagerDLL vdll=voyagerDLL.INSTANCE;
String err="";
int errB=256;
Pointer pathState=vdll.PathReaderOpen("C:\\Modelrun\\FieldsErtel\\05e05i05i05aV76FE\\AMPATHS.PTH", err, errB);
int nTables=vdll.PathReaderGetNumTables(pathState);
String[] tNames=new String[nTables];
int tnr=vdll.PathReaderGetTableNames(pathState, tNames);
int prZones=vdll.PathReaderGetNumZones(pathState);
@AndrewTheTM
AndrewTheTM / loc_IntersectionCalc
Created November 20, 2012 14:06
Law of Cosines
//Law of cosines - cos angle = ((Ladj side 1)^2+(Ladj side 2)^2-(Lopposite)^2) / (2(Ladj side 1)(Ladj side 2))
double LAdj1=0;
double LAdj2=0;
double LOpp=0;
LAdj1=Math.sqrt(Math.pow(B.getX()-A.getX(),2)+Math.pow(B.getY()-A.getY(),2));
LAdj2=Math.sqrt(Math.pow(C.getX()-B.getX(),2)+Math.pow(C.getY()-B.getY(),2));
LOpp=Math.sqrt(Math.pow(C.getX()-A.getX(),2)+Math.pow(C.getY()-A.getY(),2));
theta=Math.acos((Math.pow(LAdj1, 2)+Math.pow(LAdj2, 2)-Math.pow(LOpp, 2))/(2*LAdj1*LAdj2));
@AndrewTheTM
AndrewTheTM / selectLink
Created January 25, 2013 15:16
Extending my Path2CSV example to include Selected Links
@AndrewTheTM
AndrewTheTM / gawk_getfirstlast
Created January 25, 2013 15:22
Gets the first and last fields from each record. Works on unequal-length records.
gawk 'BEGIN {FS=","};{print $1,",",$NF}' amPaths.csv >amOD.CSV
@AndrewTheTM
AndrewTheTM / NAICS2EmpType
Created April 19, 2013 18:14
OKI/MVRPC Model NAICS 2-digit to Employment Type IDs
IF [NAICS2]=11 THEN
Output="Agr"
ELSEIF [NAICS2]>11 AND [NAICS2]<31 THEN
Output="Min"
ELSEIF [NAICS2]>=31 AND [NAICS2]<33 THEN
Output="Man1"
ELSEIF [NAICS2]=33 THEN
Output="Man2"
ELSEIF [NAICS2]=42 THEN
Output="Who"