This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT attrelid::regclass, attnum, attname | |
FROM pg_attribute | |
WHERE attrelid = 'myschema.mytable'::regclass | |
AND attnum > 0 | |
AND NOT attisdropped | |
ORDER BY attnum; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.core.display import Image | |
Image(filename='test.png') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_adjacent_cells( self, x_coord, y_coord ): | |
result = {} | |
for x,y in [(x_coord+i,y_coord+j) for i in (-1,0,1) for j in (-1,0,1) if i != 0 or j != 0]: | |
if (x,y) in grid.cells: | |
result[(x,y)] = grid.cells[(x,y)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Extract PDF text using PDFMiner. Adapted from | |
http://stackoverflow.com/questions/5725278/python-help-using-pdfminer-as-a-library | |
""" | |
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter#process_pdf | |
from pdfminer.pdfpage import PDFPage | |
from pdfminer.converter import TextConverter | |
from pdfminer.layout import LAParams |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'krishnab' | |
from time import sleep | |
from blessings import Terminal | |
from progressive.bar import Bar | |
from progressive.tree import ProgressTree, Value, BarDescriptor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OptionalDecoratorDecorator(object): | |
def __init__(self, decorator): | |
self.deco = decorator | |
def __call__(self, func): | |
self.deco = self.deco(func) | |
self.func = func | |
def wrapped(*args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE EXTENSION postgis; | |
CREATE EXTENSION postgis_topology; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
update census_tracts_2014 | |
set council_district = t1.dist | |
from (select council_districts.dist, census_tracts_2014.affgeoid, council_districts.geom | |
from census_tracts_2014 inner join council_districts | |
on | |
ST_Intersects(census_tracts_2014.geom, ST_Transform(council_districts.geom,4269))) t1 | |
where | |
ST_Intersects(census_tracts_2014.geom, ST_Transform(t1.geom,4269)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION AVERAGE4 ( | |
V1 NUMERIC, | |
V2 NUMERIC, | |
V3 NUMERIC, | |
V4 NUMERIC) | |
RETURNS NUMERIC | |
AS $FUNCTION$ | |
DECLARE | |
COUNT NUMERIC; | |
TOTAL NUMERIC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- lower case table names -- the psql friendly and more reader-friendly way | |
SELECT 'ALTER TABLE ' || quote_ident(t.table_schema) || '.' | |
|| quote_ident(t.table_name) || ' RENAME TO ' || quote_ident(lower(t.table_name)) || ';' As ddlsql | |
FROM information_schema.tables As t | |
WHERE t.table_schema NOT IN('information_schema', 'pg_catalog') | |
AND t.table_name <> lower(t.table_name) | |
ORDER BY t.table_schema, t.table_name; | |
--generates something like this | |
--ALTER TABLE public."SPRINT" RENAME TO sprint; |