Skip to content

Instantly share code, notes, and snippets.

View erochest's full-sized avatar

Eric Rochester erochest

View GitHub Profile
@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
" 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 / 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)
@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 / 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 / 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)),))
class Freq
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :input_text
validates :input_text, :presence => true
def initialize(attributes = {})
@erochest
erochest / omg.py
Created October 20, 2011 13:18
OMG, and I thought this was a good idea.
# This file should be name omg.ptl.
class PageTemplate(object):
def _corner [html] (self):
'This gets output too. What fun!<br />\n'
if self._project():
return self._project().upper()
else:
'<font size="-1">Linguistic Atlas Projects</font>'
@erochest
erochest / di.py
Created October 5, 2011 19:54
Dependency Injection (DI) or Inversion of Control (IoC) in Python
#!/usr/bin/env python
"""\
A short explanation of dependency injection and how to use to make testing
easier.
Maybe this should be a mocking guide, because everything's going to be a mock
object.
@erochest
erochest / fix_vim_perms.rb
Created September 29, 2011 20:06
Script to fix issues with Janus on Windows.
require 'pathname'
GVIMRC = <<EOF
" undefine all the custom NERDTree-aware commands.
" From https://github.com/carlhuda/janus/issues/174
cunabbrev cd