Skip to content

Instantly share code, notes, and snippets.

View jasonbot's full-sized avatar
🥉

Jason Scheirer jasonbot

🥉
View GitHub Profile
@jasonbot
jasonbot / convert2to3.py
Created February 3, 2014 16:41
Alternative to the clunky 2to3 command line script. Streamlined function that will take a Python 2 code string (as unicode), feed it through lib2to3 using all its converters, then return a Python 3 code string.
# coding: utf-8
import lib2to3
import lib2to3.fixes
import lib2to3.refactor
__all__ = ["code_to_py3"]
all_fixes = ["lib2to3.fixes.fix_{}".format(l)
for l in lib2to3.refactor.get_all_fix_names("lib2to3.fixes")]
@jasonbot
jasonbot / terrible_trace.py
Created January 29, 2014 00:45
A terrible thing: print the source of every line of Python code as it executes in your scripts. Please don't actually use it. Please.
import inspect
import sys
def tracefunction(frame, event, arg):
if event == "line":
info = inspect.getframeinfo(frame)
fname, lineno, fn = info.filename, info.lineno, info.function
with open(fname, 'rb') as f:
line = [line.rstrip() for line in f][lineno - 1]
print "Function: {} (in file {}:{}) | {}".format(fname, fn, lineno, line)
@jasonbot
jasonbot / runthroughredlands.json
Last active January 3, 2016 17:09
Run Through Redlands Course
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jasonbot
jasonbot / wrap_out_writer.py
Created December 9, 2013 18:08
Use to make GP tools compatible with multiprocessing (usually they replace sys.stdout with a GP version that doesn't have all the same methods). Just call fix_stdout() after importing arcpy.
import arcpy
import sys
class WrappedStream(object):
"Wraps sys.stdout to have all the usual methods of a file object"
def __init__(self, wrap):
self._wrap = wrap
def close(self, *args, **kw):
try:
@jasonbot
jasonbot / layers.py
Last active December 27, 2015 15:18
List of layers by feature type
point_layers = []
line_layers = []
polygon_layers = []
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.isFeatureLayer:
# Try to get .shapeType attribute from data source.
# For XY event layers there is no shape type (it's a
# CSV or something) so assume it's a Point layer.
shape_type = getattr(arcpy.Describe(lyr.dataSource),
@jasonbot
jasonbot / parkingmap.json
Last active December 25, 2015 23:49
Parking Map
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jasonbot
jasonbot / RotW.py
Last active December 25, 2015 02:49
def join_string(fn):
def fn_(*a, **k):
return "".join(reversed(list(fn(*a, **k))))
return fn_
@join_string
def binary_string(number, bit_count):
for bit in xrange(bit_count):
yield "1" if number & 1 == 1 else "0"
number = number >> 1
@jasonbot
jasonbot / .vimrc
Last active December 24, 2015 08:29
My minimal .vimrc for Windows
set tabstop=4
set shiftwidth=4
set expandtab
set backspace=indent,eol,start
set guifont=Consolas:h10:cDEFAULT
set ruler
colorscheme zenburn
syntax on
filetype indent plugin on
set directory+=$HOME
import os
import re
import zipfile
current_path = os.path.dirname(os.path.abspath(__file__))
out_zip_name = os.path.join(current_path,
os.path.basename(current_path) + ".esriaddin")
BACKUP_FILE_PATTERN = re.compile(".*_addin_[0-9]+[.]py$", re.IGNORECASE)
@jasonbot
jasonbot / notificationicon.pyw
Last active August 20, 2021 14:39
A class to create/manage a raw Windows Tray Icon for an app, with popup menus
import ctypes
import ctypes.wintypes
import os
import threading
import Queue
import uuid
__all__ = ['NotificationIcon']
# Create popup menu