Skip to content

Instantly share code, notes, and snippets.

@raykendo
raykendo / mssql_connect.py
Created Sep 17, 2020
Connecting To SQL Server using Python 3
View mssql_connect.py
#!/usr/bin/env python3
# an example of connecting to a SQL Server database using Python 3
# automatically closes the db connection after use
import pyodbc
from contextlib import contextmanager
# pyodbc wiki: https://github.com/mkleehammer/pyodbc/wiki
# example based on https://docs.microsoft.com/en-us/sql/connect/python/pyodbc/step-3-proof-of-concept-connecting-to-sql-using-pyodbc?view=sql-server-ver15
@raykendo
raykendo / viewGoogleMaps.py
Created Feb 19, 2020
A Python Script for automating looking up addresses on Google Maps
View viewGoogleMaps.py
#!/usr/bin/python
# viewGoogleMaps.py
# author: Ken Doman (github.com/raykendo)
# purpose: Looking up addresses through Google Maps automagically
# requirements: python 2 or 3, selenium for python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
@raykendo
raykendo / ArcGIS-JSAPI-MapClickByQueryHack.md
Last active Jul 6, 2018
ArcGIS-JSAPI: Clicking on a webmap without clicking on a webmap
View ArcGIS-JSAPI-MapClickByQueryHack.md

Clicking on a map without clicking on a map

An ArcGIS JavaScript API hack

Purpose: I have a map application with a list of results from a query. When I click on one of the items in the result list, I wanted the map to zoom to the associated feature, and trigger a click that shows the result in a popup.

Library: ArcGIS JavaScript API

Version: tested on versions 3.9-3.13.

@raykendo
raykendo / BigQueryTask.js
Last active Jul 4, 2018
ArcGIS JSAPI Hack - Getting around the 1000 results limit for queries
View BigQueryTask.js
/** globals define */
define([
"dojo/_base/declare",
"dojo/Deferred",
"esri/tasks/query",
"esri/tasks/QueryTask",
"esri/request"
], function (
declare, Deferred, Query, QueryTask, esriRequest
) {
@raykendo
raykendo / file.js
Last active Mar 14, 2018
Throttle Ajax Requests
View file.js
(function () {
// ajax function from https://gist.github.com/Xeoncross/7663273
function ajax(url, callback, data, x) {
try {
x = new (this.XMLHttpRequest || ActiveXObject)("MSXML2.XMLHTTP.3.0");
x.open(data ? "POST" : "GET", url, 1);
x.setRequestHeader("X-Requested-With", "XMLHttpRequest");
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
x.onreadystatechange = function () {
@raykendo
raykendo / file.js
Last active Jan 15, 2018
Get URL query or hash parameter
View file.js
(function () {
//source: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
// modified to also check hash
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?#&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
@raykendo
raykendo / delete-stuff2.py
Last active Aug 16, 2017
Removing junk files from a folder recursively (Python)
View delete-stuff2.py
#!/usr/bin/env python
#
# delete-stuff2.py: delete specific files and folders within subdirectories of a folder.
# by raykendo
# Python 2.7+
#
import os
import stat
import sys
@raykendo
raykendo / example.js
Created Feb 16, 2017
Getting max distance between a shape and a reference point
View example.js
(function () {
"use strict";
//...
/**
* defining {object} point
* @property {number} x - x coordinate for the point.
* @property {number} y - y coordinate for the point.
*/
@raykendo
raykendo / CleanWebMapRequest.js
Created Feb 10, 2017
Cleaning Export Web Map request plugin
View CleanWebMapRequest.js
/**
* Some people just need a paper map. ArcGIS Server provides a service to turn a web map into an image, pdf, or other file
* The process to generate these documents can be long and intensive (in relative web terms), taking up to 2 minutes to generate
* a document.
*/
/* globals: define*/
define([
"dojo/_base/lang",
"dojo/_base/array",
"dojo/json",
@raykendo
raykendo / index.html
Last active Sep 23, 2016
Mapillary JS + ArcGIS JavaScript API 4.x Example
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mapillary-JS + ArcGIS JSAPI 4.x example</title>
<link rel="stylesheet" href="https://unpkg.com/mapillary-js@1.7.1/dist/mapillary-js.min.css">
<link rel="stylesheet" href="https://js.arcgis.com/4.0/esri/css/main.css">
<script type="text/javascript">
dojoConfig = {
async: true,