Skip to content

Instantly share code, notes, and snippets.

View jasonbot's full-sized avatar
🥉

Jason Scheirer jasonbot

🥉
View GitHub Profile
@jasonbot
jasonbot / textmetrics.py
Created January 31, 2012 21:50
Get the width and height (in inches) of a string using the Win32 CTypes APIs.
import ctypes
import ctypes.wintypes
class Constants(object):
"Container for constants found in win32 headers"
WS_OVERLAPPED = 0x00000000L
WS_POPUP = 0x80000000L
WS_CHILD = 0x40000000L
WS_MINIMIZE = 0x20000000L
WS_VISIBLE = 0x10000000L
@jasonbot
jasonbot / rowsasdicts.py
Last active January 31, 2019 20:41
Get dicts instead of lists from an arcpy.da SearchCursor
def rows_as_dicts(cursor):
colnames = cursor.fields
for row in cursor:
yield dict(zip(colnames, row))
with arcpy.da.SearchCursor(r'c:\data\world.gdb\world_cities', '*') as sc:
for row in rows_as_dicts(sc):
print row['CITY_NAME']
@jasonbot
jasonbot / rowsasnamedtuples.py
Created July 12, 2012 19:37
Get namedtuples instead of lists from an arcpy.da SearchCursor
import collections
def rows_as_namedtuples(cursor):
col_tuple = collections.namedtuple('Row', cursor.fields)
for row in cursor:
yield col_tuple(*row)
with arcpy.da.SearchCursor(r'c:\data\world.gdb\world_cities', '*') as sc:
for row in rows_as_namedtuples(sc):
print sc.CITY_NAME
@jasonbot
jasonbot / daupdatedicts.py
Last active March 24, 2020 19:39
Update cursor with dictionary rows
def rows_as_update_dicts(cursor):
colnames = cursor.fields
for row in cursor:
row_object = dict(zip(colnames, row))
yield row_object
cursor.updateRow([row_object[colname] for colname in colnames])
with arcpy.da.UpdateCursor(r'c:\data\world.gdb\world_cities', ['CITY_NAME']) as sc:
for row in rows_as_update_dicts(sc):
row['CITY_NAME'] = row['CITY_NAME'].title()
@jasonbot
jasonbot / gist:5162544
Created March 14, 2013 15:55
All the modules bundled with Anaconda
['ArgImagePlugin',
'BaseHTTPServer',
'Bastion',
'BdfFontFile',
'BmpImagePlugin',
'BufrStubImagePlugin',
'CGIHTTPServer',
'Canvas',
'ConfigParser',
'ContainerIO',
@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
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 / .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
@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 / 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.