Skip to content

Instantly share code, notes, and snippets.

View arvsrao's full-sized avatar

Arvind ರಾವ್ arvsrao

View GitHub Profile
@arvsrao
arvsrao / odbc_setup_macos.md
Last active July 28, 2023 04:54
Guide to accessing MS SQL Server in Mac OS X via PyODBC

Since I spent essentially two full days figuring out how to access a corporate MS SQL database pythonicly, I figured I should leave some notes, for future reference and to aid other souls looking to do the same.

These instructions and the commands that follow, were executed on a MAC OS 10.8.3 system. Additionally, I found this blog [post][1] especially helpful during the debugging process.

On mac os, there is a default ODBC manager, iODBC. Other Unix based systems tend to use [unixODBC][2]. Look elsewhere for a discussion about the differences between these driver managers. The only feature we care about is being able to connect to SQL databases through [pyodbc][3], and at the time of this writing [pyodbc][3] requires iODBC as its manager.

Start by installing freeTDS libraries. FreeTDS allows unix programs to talk natively with MS SQL and SyBase databases.

brew intsall freetds
@arvsrao
arvsrao / pi_day.py
Last active July 28, 2023 04:53
Monte Carlo Approximation of PI
from random import uniform
"""
Monte Carlo approximation of PI
Sample run:
person@pc-1 ~/> python pi_day.py
approximation of PI: 3.1427
"""
def generatePoints():
@arvsrao
arvsrao / randomSegments.py
Created May 14, 2014 08:23
code for generating the empirical distribution of max-segment lengths
from random import uniform
from numpy import array
from math import pi
def MaxArc(N):
cuts = [ uniform(0, 2*pi) for x in range(N) ]
cuts.sort()
other = [x for x in cuts]
other.insert(0, other.pop())
cuts[0]+=2*pi
cost cost / person
Yoesmite Park Fees $30 $6
Groceries $170 $34
lyft ride from SFO to SF $46 $11*
$246 $51

* the actually cost was $66, before applying a $20 free ride credit. And subsequently the $46 is divided across the group (excluding me).

@arvsrao
arvsrao / verify_so3.py
Last active July 28, 2023 04:52
verify SU(2) maps to SO(3)
from sympy import *
a = Symbol('a', real=true)
b = Symbol('b', real=true)
c = Symbol('c', real=true)
d = Symbol('d', real=true)
x = a + I*b
z = c + I*d
from sympy import *
from sympy.solvers import solve
x = Symbol('x', real=true)
y = Symbol('y', real=true)
x0 = Symbol('x0', real=true)
x1 = Symbol('x1', real=true)
x2 = Symbol('x2', real=true)
y0 = Symbol('y0', real=true)
y1 = Symbol('y1', real=true)
def fact(n):
if (n <= 0):
return 0
elif ( n < 3 ):
return n
else:
return fact(n-1) + fact(n-2)
def memoize(f):
from sympy import Matrix
from sympy.abc import a,b
from sympy.physics.quantum import TensorProduct
A = Matrix([[a, -b, 0],
[b, a, 0],
[0, 0, 1]])
#Embedding into tensor space.
E = Matrix([[1, 0, 0, 0, 0, 0],
from random import uniform
from numpy import arccos, pi, array, cos, sin, cross, sqrt
from sympy.abc import a,b
from sympy import Matrix, pprint
from itertools import product
from sympy.physics.quantum import TensorProduct
# A \otimes \rho_{d}
def orderedTensorProduct(d):
@arvsrao
arvsrao / generate_random_so3_matrix.py
Created March 17, 2020 21:05
Generate a random SO(3) matrix.
from random import uniform
from math import cos, sin, pi, acos
from sympy import Symbol, I, Matrix, factor, simplify, im, re, expand, true
EPSILON = 0.0001
MAX_ITERATIONS = 1000
a = Symbol('a', real=true)
b = Symbol('b', real=true)
c = Symbol('c', real=true)