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
/* | |
QUERY Apple Messages sqlite database | |
at ~/Library/Messages/chat.db | |
*/ | |
select | |
datetime(m.date + strftime('%s','2001-01-01'), 'unixepoch', 'localtime') as dt | |
, m.text | |
, c.chat_identifier |
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
// Utilities | |
var td_mill = { | |
second: 1000 | |
} | |
td_mill.minute = td_mill.second * 60; | |
td_mill.hour = td_mill.minute * 60; | |
td_mill.day = td_mill.hour * 24; |
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
''' | |
Transform Bank of America PDF text into tables. | |
Example: | |
python parse_boa_statements.py test/joint_dump.txt test/pers_dump.txt --output test/combined.csv | |
Example of original PDF text (copy/pasted from PDF): | |
MISTER NAME | Account # 999 99999 9999 | November 24, 2015 to December 24, 2015 | |
Your checking account | |
Page 3 of 4 |
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 os | |
import datetime | |
import time | |
import shove | |
SEC = 1 | |
MIN = SEC * 60 | |
HOUR = MIN * 60 | |
DAY = HOUR * 24 |
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
''' | |
Move a file to a backup, if the file exists. If context manager statement fails, then restore the backup. | |
''' | |
class FakeException(Exception): | |
pass | |
def create_backup_path(path, backup_ext='.bak'): | |
backup_path = path | |
while backup_path == path or os.path.exists(backup_path): |
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 string | |
import re | |
import jinja2 | |
def split_many(astring, *split_on_chars, **kwargs): | |
""" | |
Split a string on many values. | |
:param split_on_chars: string to split | |
:type split_on_chars: basestring |
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 string | |
import re | |
import jinja2 | |
acceptable_punc = set('#$._-') | |
all_punctuation = set(string.punctuation) | |
ignore_punc = all_punctuation.difference(acceptable_punc) |
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 get_dependencies(node, edges_list, depth=0): | |
if depth > len(edges_list): | |
raise Exception('Circular dependency somewhere.') | |
seen_nodes = set() | |
for from_node, to_node in edges_list: | |
if from_node == node: | |
seen_nodes.add(from_node) | |
if to_node in seen_nodes: | |
continue | |
yield to_node |
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 itertools | |
import collections | |
def is_non_string_sequence(seq): | |
return isinstance(seq, collections.Sequence) and not isinstance(seq, basestring) | |
def is_dict(d): | |
return isinstance(d, collections.Mapping) or hasattr(d, 'iteritems') and not isinstance(d, basestring) | |
def iterable_paths(o, level=0): | |
if is_dict(o): | |
seqs = [] | |
for k, v in o.iteritems(): |
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 collections | |
import operator | |
import json | |
def merge_dicts(dicts=None, create_key_func=None): | |
""" Efficiently sort and merge different dictionary collections """ | |
sort_keys = collections.defaultdict(list) | |
for dct_ix, dcts in enumerate(dicts): | |
for record_ix, record in enumerate(dcts): | |
sortkey = create_key_func(record) |
NewerOlder