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
# Mathieu Blondel, September 2010 | |
import numpy as np | |
from numpy import linalg | |
import cvxopt | |
import cvxopt.solvers | |
def linear_kernel(x1, x2): | |
return np.dot(x1, x2) |
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 time | |
class Timer: | |
def __enter__(self): | |
self.start = time.clock() | |
return self | |
def __exit__(self,*args): | |
self.end = time.clock() | |
self.interval = self.end-self.start |
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
. repeat last command | |
>G increase the indentation from current line until end of file | |
A appends at the end of current line | |
f{char} look ahead for specified character | |
; repeat last search of f command | |
, repeat last search of f command in reverse | |
cw deletes to end of word and drops into Insert mode | |
# moving around | |
gg go to top of file |
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
# http://stackoverflow.com/questions/4060221/how-to-reliably-open-a-file-in-the-same-directory-as-a-python-script?utm_source=feedly | |
__location__ = os.path.realpath( | |
os.path.join(os.getcwd(), os.path.dirname(__file__))) |
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
# http://www.mingw.org/wiki/Getting_Started | |
# http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/ | |
# install MinGW in C:\MinGW | |
# Add C:\MinGW\bin to PATH | |
# Create distutils.cfg in C:\Python27\Lib\distutils\distutils.cfg to be: | |
# [build] | |
# compiler=mingw32 | |
# http://stackoverflow.com/questions/6034390/compiling-with-cython-and-mingw-produces-gcc-error-unrecognized-command-line-o |
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
# generate new key | |
ssh-keygen -t rsa -C "your-email-address" | |
# attach new key | |
eval "$(ssh-agent)" | |
ssh-add ~/.ssh/id_rsa_NEW | |
# create config | |
vi config |
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 sys | |
def set_trace(): | |
from IPython.core.debugger import Pdb | |
Pdb(color_scheme='Linux').set_trace(sys._getframe().f_back) | |
def debug(f, *args, **kwargs): | |
from IPython.core.debugger import Pdb | |
pdb = Pdb(color_scheme='Linux') | |
return pdb.runcall(f, *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
def NewTorIP(): | |
s = socket.socket() | |
s.connect(('localhost', 9051)) | |
s.send("AUTHENTICATE\r\n") | |
r = s.recv(1024) | |
if r.startswith('250'): | |
s.send("signal NEWNYM\r\n") | |
r = s.recv(1024) | |
if r.startswith('250'): | |
return True |
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 -*- | |
""" | |
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, | |
add booleans?, |
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
# http://stackoverflow.com/questions/13570178/itter-from-some-odbc-connection-to-pandas-table-with-out-a-csv | |
import pyodbc | |
import pandas.io.sql as psql | |
cnxn = pyodbc.connect(your_connection_info) | |
cursor = cnxn.cursor() | |
sql = ("""SELECT * FROM Source""") | |
df = psql.frame_query(sql, cnxn) |