Skip to content

Instantly share code, notes, and snippets.

@c0ldlimit
c0ldlimit / process_cursor.py
Created November 16, 2012 17:11 — forked from phobson/process_cursor.py
Process a pyodbc database cursor into a numpy record array or pandas dataframe
import pyodbc
import numpy as np
import datetime
import pandas
def processCursor(cur, dataframe=False):
datatypes = []
colinfo = cur.description
for col in colinfo:
if col[1] == unicode:
@c0ldlimit
c0ldlimit / print_traceback.py
Created November 16, 2012 17:12
Python: Printing Exception Traceback #c0ldlimit #python #traceback
#Traceback.format_exc() or sys.exc_info() will yeild more info if thats what you want.
import traceback
import sys
try:
do_stuff()
except Exception, err:
print traceback.format_exc()
#or
@c0ldlimit
c0ldlimit / commentblock_vim
Created November 16, 2012 17:13
Vim: Commenting out a block of code
# http://stackoverflow.com/questions/2561418/how-to-comment-out-a-block-of-python-code-in-vim
Ctrl-v
select text
Shift-I
comment keys
Esc
@c0ldlimit
c0ldlimit / git_newrepo
Created November 16, 2012 17:14
Git: Push a new or existing repo to Github
# Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/c0ldlimit/vimcolors.git
git push -u origin master
# Push an existing repository from the command line
@c0ldlimit
c0ldlimit / git_ignoreeverythingbut
Created November 16, 2012 17:15
Git: Ignore all but a few files
# http://stackoverflow.com/questions/987142/make-gitignore-ignore-everything-except-a-few-files
# Ignore everything
*
# But not these files...
!script.pl
!template.latex
!.gitignore
@c0ldlimit
c0ldlimit / http_request.py
Created November 16, 2012 17:15
Python: Submitting HTTP Requests
# http://www.blog.pythonlibrary.org/2012/06/08/python-101-how-to-submit-a-web-form/
# with urllib
import urllib
import urllib2
import webbrowser
url = "http://duckduckgo.com/html"
data = urllib.urlencode({'q': 'Python'})
@c0ldlimit
c0ldlimit / debugging_tips.py
Created November 16, 2012 17:16
Python: Debugging
# http://aymanh.com/python-debugging-techniques
# http://nblock.org/2011/11/15/pdb-cheatsheet/
import pdb; pdb.set_trace()
@c0ldlimit
c0ldlimit / nan_check.py
Created November 16, 2012 17:16
Python: Checking if nan
import math
x=float('nan')
math.isnan(x)
@c0ldlimit
c0ldlimit / python_unique.py
Created November 16, 2012 17:17
Python: Unique List #(python unique list)
# http://www.peterbe.com/plog/uniqifiers-benchmark
def f5(seq, idfun=None):
# order preserving
if idfun is None:
def idfun(x): return x
seen = {}
result = []
for item in seq:
@c0ldlimit
c0ldlimit / date_arithmetic.py
Created November 16, 2012 17:18
Python: Date Arithmetic
from datetime import date, timedelta
d=date.today()-timedelta(days=days_to_subtract)