Skip to content

Instantly share code, notes, and snippets.

@hunterowens
hunterowens / connect_and_load.py
Last active December 9, 2023 16:27
Pandas and MSSQL
import pymssql
import pandas as pd
## instance a python db connection object- same form as psycopg2/python-mysql drivers also
conn = pymssql.connect(server="172.0.0.1", user="howens",password="some_fake_password", port=63642) # You can lookup the port number inside SQL server.
## Hey Look, college data
stmt = "SELECT * FROM AlumniMirror..someTable"
# Excute Query here
df = pd.read_sql(stmt,conn)
@fonnesbeck
fonnesbeck / map.geojson
Created August 26, 2013 02:59
via:geojson.io
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bistaumanga
bistaumanga / DTW_python.py
Created July 17, 2013 19:33
Dynamic Time warping implemented in python
'''Implementation and Demostration of Dynamic Time Warping
Requires : python 2.7.x, Numpy 1.7.1, Matplotlib, 1.2.1'''
from math import *
import numpy as np
import sys
def DTW(A, B, window = sys.maxint, d = lambda x,y: abs(x-y)):
# create the cost matrix
A, B = np.array(A), np.array(B)
@audreyfeldroy
audreyfeldroy / pypi-release-checklist.md
Last active April 9, 2026 05:34
My PyPI Release Checklist
  • Update HISTORY.md
  • Commit the changes:
git add HISTORY.md
git commit -m "Changelog for upcoming release 0.1.1."
  • Update version number (can also be minor or major)
bumpversion patch
@binarymatt
binarymatt / gist:5978228
Created July 11, 2013 19:00
python is awesome
import collections
def extract_top_ten(str):
return collections.Counter(str.split()).most_common(10)
@tmcw
tmcw / d3.md
Last active December 6, 2022 14:04
Accompaniment to dcjq

This is a more wordy, narrative accompaniment to my pretty bare presentation about d3 that I gave to the jQuery DC Meetup.

What is d3?

  • Not a chart library (though you can make charts with it)
  • Not a map library (though you can make maps with it)

Which is to say, d3 can be used for building things, but the 'atomic parts' are lower-level than bar graphs or projections or so on. This is a powerful fact. It also means that d3 is a good basis for simple interfaces, like Vega.js, that make its power accessible in other ways.

  • Not a compatibility layer (it doesn't work with bad browsers)
@fonnesbeck
fonnesbeck / matrix_2diff.py
Created May 5, 2013 19:52
Matrix for second differneces
import numpy as np
I2 = 2*np.eye(8)
E = -np.diag(np.ones((7)), k=-1)
@fonnesbeck
fonnesbeck / sort_dict.py
Last active December 17, 2015 00:38
Sort dict by value
aDictionary = {'a':3, 'b':-4, 'c':3.14}
sorted(aDictionary, key=lambda x: aDictionary[x])
@nouiz
nouiz / numba_bug.py
Last active June 8, 2020 16:46
Test how to make a Theano op that call Numba.
import numba
import numpy
#The filter2d with the same signature as Theano
#but not a class method.
def filter2d_theano(node, inputs, outputs):
image, filt = inputs
M, N = image.shape
Mf, Nf = filt.shape
@tristanwietsma
tristanwietsma / adaboost.py
Created April 30, 2013 01:13
AdaBoost Python implementation of the AdaBoost (Adaptive Boosting) classification algorithm.
from __future__ import division
from numpy import *
class AdaBoost:
def __init__(self, training_set):
self.training_set = training_set
self.N = len(self.training_set)
self.weights = ones(self.N)/self.N
self.RULES = []