Skip to content

Instantly share code, notes, and snippets.

@adamb70
adamb70 / spreadsheet-col-index.py
Created February 18, 2018 01:55
Converts spreadsheet-style column names (A, B, AA, etc) of any length into an integer index, such that A==0, B==1, AA==26, etc. Use upper or lower case.
def col(letters):
""" Convert column letters into zero-indexed number """
letters = letters.lower()
num = 0
for l in letters[:-1]:
num += (ord(l) - 96) * 26
num += (ord(letters[-1]) - 96)
return num - 1
def haversine(lat1, lon1, lat2, lon2, miles=False):
phi1, phi2, dlat, dlon = map(radians, [lat1, lat2, lat2-lat1, lon2-lon1])
radius = 6371
if miles:
radius = 3956
a = sin(dlat/2)**2 + cos(phi1) * cos(phi2) * sin(dlon/2)**2
c = 2 * asin(sqrt(a))
return radius * c
@adamb70
adamb70 / day11.py
Last active December 13, 2016 14:00
from itertools import combinations
class Generator(object):
def __init__(self, element):
self.elem = element
def __repr__(self):
return str(self.elem) + ' Generator'
@adamb70
adamb70 / Blowfish-Compat.py
Created April 15, 2015 22:59
Decrypt and encrypt Blowfish-Compat format files in Python 2.7
import os
from Crypto.Cipher import _Blowfish
from struct import pack
def encrypt(infilepath, outfilepath, key):
""" Encrypt the specified file with the specified
key and output to the chosen output file."""
size = os.path.getsize(infilepath)