Skip to content

Instantly share code, notes, and snippets.

@c0ldlimit
c0ldlimit / svm.py
Created April 30, 2013 14:10 — forked from mblondel/svm.py
# 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)
@c0ldlimit
c0ldlimit / gist:5431958
Created April 22, 2013 01:58
#python #context #handlers
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
@c0ldlimit
c0ldlimit / gist:5426596
Last active December 16, 2015 11:19
#vim cheatsheet
. 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
@c0ldlimit
c0ldlimit / gist:5421209
Created April 19, 2013 15:46
#python open a file in the same directory as a python script
# 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__)))
@c0ldlimit
c0ldlimit / gist:5376865
Created April 13, 2013 04:01
#python building c extensions and getting rid of that "cannot find vcvarsall.bat" on window 7
# 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
@c0ldlimit
c0ldlimit / gist:5376713
Last active December 16, 2015 04:19
#github #git multiple keys and multiple github accounts
# 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
@c0ldlimit
c0ldlimit / gist:5325027
Created April 6, 2013 05:48
#python #ipython Put into startup folder in profile_default for better debugging
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)
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
# -*- 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?,
@c0ldlimit
c0ldlimit / gist:5187339
Created March 18, 2013 14:01
#python #pandas #sql Pyodbc query to dataframe
# 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)