Skip to content

Instantly share code, notes, and snippets.

View erochest's full-sized avatar

Eric Rochester erochest

View GitHub Profile
@erochest
erochest / access-layers.py
Created November 16, 2011 17:45
Exploring calling QuickExport from a Python script tool and passing a Layer object through..
import arcpy
# Parameter 0, whatever the name, should have type "Feature Layer".
obj = arcpy.GetParameter(0)
# This prints out all of the properties and methods on the object that gets
# passed in as Parameter(0). I haven't looked closely, but we should be able
# to pass this directly to
arcpy.AddMessage('obj = %r' % (repr(dir(obj)),))
@erochest
erochest / test-for-db.py
Created November 30, 2011 16:18
Testing for existence of a Postgres database
from contextlib import closing
def db_exists(cxn, db_name):
"""\
This takes a connection to a Postgres object and db name and tests whether it
exists or not.
"""
with closing(cxn.cursor()) as c:
c.execute('SELECT COUNT(*) FROM pg_database WHERE datname=%s;', [db_name])
(count,) = c.fetchone()
@erochest
erochest / scratch.coffee
Created February 3, 2012 16:43
Playing around with a CoffeeScript console on a Prism document page.
# http://jashkenas.github.com/coffee-script/
# https://developer.mozilla.org/en/JavaScript/Reference/
# http://docs.jquery.com/Main_Page
# http://mbostock.github.com/d3/
# 1.
#
# Alert!
alert('Danger, Will Robinson!')
# 2.
@erochest
erochest / get-extent.py
Created February 3, 2012 20:19
Getting the extent for a layer in arcpy
desc = arcpy.Describe('poly_landmarks')
ext = desc.extent
ext.upperRight.x, ext.upperRight.y
# (-73.907820000000001, 40.882078)
ext.lowerRight.x, ext.lowerRight.y
# (-73.907820000000001, 40.679648)
ext.upperLeft.x, ext.upperLeft.y
# (-74.047184999999999, 40.882078)
ext.lowerLeft.x, ext.lowerLeft.y
# (-74.047184999999999, 40.679648)
" Run PHP Unit tests.
nmap \Tu :w<CR>:call Send_to_Tmux("rake php:unit\n")<CR>
" Run Cucumber, vanilla.
nmap \Tc :w<CR>:call Send_to_Tmux("rake cucumber:default\n")<CR>
" Re-run Cucumber.
nmap \Tr :w<CR>:call Send_to_Tmux("rake cucumber:rerun\n")<CR>
@erochest
erochest / generate-html.sh
Created March 21, 2012 17:46
A script I wrote in Literate Haskell using Shelly
#!/bin/sh
# pandoc -f markdown+lhs -t html5 --smart --css https://raw.github.com/richleland/pygments-css/master/default.css s5topdf.lhs
# pandoc -f markdown+lhs -t html5 --smart --css s5topdf.css s5topdf.lhs
pandoc -f markdown+lhs -t html5 --smart s5topdf.lhs
@erochest
erochest / reset-solr
Created April 12, 2012 15:11 — forked from waynegraham/gist:2355797
Delete solr index with curl
curl http://localhost:8983/solr/update?commit=true -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>'
@erochest
erochest / broken.php
Created April 12, 2012 15:57
What's wrong with this?
protected function _addFacetMappings()
{
$sql = <<<SQL
INSERT INTO `{$this->_db->prefix}solr_search_facets`
(element_id, name, element_set_id, is_facet, is_displayed, is_sortable)
VALUES (?, ?, ?, ?, ?, ?);
SQL;
$stmt = $this->_db->prepare($sql);
// These get inserted fine.
[Exhibits]
id-column=eid
result-type=Exhibits
table={$prefix}_exhibits
flag=public
tagged=yes
[Exhibits.title]
[Exhibits.description]
user=> (defn test-m [stemmer] [stemmer (m stemmer) (m2 stemmer)])
#'user/test-m
user=> (-> (make-stemmer "ba") test-m)
[{:word [\b \a], :index 1} 0 0]
user=> (-> (make-stemmer "bava") test-m)
[{:word [\b \a \v \a], :index 3} 1 0]
user=> (-> (make-stemmer "baba") test-m)
[{:word [\b \a \b \a], :index 3} 1 0]
user=> (-> (make-stemmer "bababa") test-m)