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
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
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
# Import Libraries | |
library(RPostgreSQL) | |
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
#' Connect to PostgreSQL database | |
#' | |
#' This takes a database name and then connects to it. | |
#' @param dname The name of the database that houses the dlhs data |
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
-- Function: template_function(OUT result boolean) | |
-- DROP FUNCTION template_function(OUT result boolean) | |
CREATE OR REPLACE FUNCTION template_function(OUT result boolean) | |
AS | |
$BODY$ | |
DECLARE | |
BEGIN |
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 pandas import read_csv | |
from urllib import urlopen | |
page = urlopen("http://econpy.pythonanywhere.com/ex/NFL_1979.csv") | |
df = read_csv(page) | |
print df | |
print df['Line'] |
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 | |
NULLIF(your_value, '')::int |
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
# -*- coding: utf-8 -*- | |
""" | |
LICENSE: BSD (same as pandas) | |
example use of pandas with oracle mysql postgresql sqlite | |
- updated 9/18/2012 with better column name handling; couple of bug fixes. | |
- used ~20 times for various ETL jobs. Mostly MySQL, but some Oracle. | |
to do: | |
save/restore index (how to check table existence? just do select count(*)?), | |
finish odbc, |
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 os import listdir | |
from os.path import isfile, join | |
onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ] |
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
import re, urllib | |
htmlSource = urllib.urlopen("http://sebsauvage.net/index.html").read(200000) | |
linksList = re.findall('<a href=(.*?)>.*?</a>',htmlSource) | |
for link in linksList: | |
print link |