Skip to content

Instantly share code, notes, and snippets.

View pmart123's full-sized avatar

Philip Martin pmart123

View GitHub Profile
@pmart123
pmart123 / string_template.py
Created April 29, 2016 15:05
Metaclass idea for file patterns
from functools import wraps
from inspect import Parameter, Signature
# ----------------------------------------------------------
# Helper Regular Expression str builders
# ----------------------------------------------------------
@pmart123
pmart123 / sqlalchemy_server_updated_at.py
Last active November 1, 2017 02:32
Creating server side updated_at trigger
from sqlalchemy import Column, event, TIMESTAMP
from sqlalchemy.sql.expression import FunctionElement
from sqlalchemy.schema import DDLElement, FetchedValue
from sqlalchemy.ext import compiler
# DDL to create set_updated_at_timestamp function
UPDATED_AT_DDL_STATEMENT = """\
CREATE OR REPLACE FUNCTION set_updated_at_timestamp()
RETURNS TRIGGER AS $$
@pmart123
pmart123 / understanding-word-vectors.ipynb
Created March 3, 2018 12:12 — forked from aparrish/understanding-word-vectors.ipynb
Understanding word vectors: A tutorial for "Reading and Writing Electronic Text," a class I teach at ITP. (Python 2.7) Code examples released under CC0 https://creativecommons.org/choose/zero/, other text released under CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pmart123
pmart123 / sqlalchemy_views.py
Last active October 10, 2018 01:54
Sqlalchemy DDL with views error
from sqlalchemy import (DDL, event, Column, TEXT, select, func,
FLOAT, CHAR, DATE, Table, table, MetaData)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.schema import CreateColumn
from sqlalchemy.sql.ddl import _CreateDropBase
from sqlalchemy.ext.compiler import compiles
class _View(Table):
__visit_name__ = 'view'
@pmart123
pmart123 / python_ideas_frozendict.py
Created October 10, 2018 16:57
Proposal for implementing frozendict in stdlib to cleanup implementing code that involves data mapping and conversions
"""
Proposal for implementing frozendict in stdlib to cleanup implementing code
that involves data mapping and conversions.
"""
from types import MappingProxyType
#####################################################
# Current way
#####################################################
@pmart123
pmart123 / crm_example.py
Last active December 19, 2018 22:44
Getting data from outlook into CRM
# https://github.com/jasonjoh/python_tutorial/blob/master/tutorial/outlookservice.py#L89
import csv
import uuid
import requests
graph_endpoint = 'https://graph.microsoft.com/v1.0{0}'
def make_api_call(method, url, token, payload=None, parameters=None):
@pmart123
pmart123 / contact_cleaner.py
Created December 19, 2018 23:05
Example code of cleaning contact names for CRM entry
from collections import namedtuple
import probablepeople as pp
ContactName = namedtuple('ContactName', 'first last')
sample_names = [
ContactName('BOB', 'SMITH, JR'),
ContactName('Robert P.', 'Kardashian, CFA, CAIA'),