Skip to content

Instantly share code, notes, and snippets.

View ekozlowski's full-sized avatar
🤔

Edward Kozlowski ekozlowski

🤔
  • Kansas City, KS
View GitHub Profile
@ekozlowski
ekozlowski / wrapped.py
Created April 27, 2017 04:33
demo of multiple levels of decorator unwrapping with __wrapped__ attribute
from functools import wraps
def w(func):
print("wrapping")
@wraps(func)
def wrapper(*args, **kwargs):
print("I'm inside the wrapper")
result = func(*args, **kwargs)
print("leaving the wrapper")
return result
@ekozlowski
ekozlowski / ed.py
Last active April 7, 2017 13:49
DFW Pythoneers Beginners Examples - 4/6/2017
# Functions! :)
def my_function_without_args():
print("No args here!")
def my_function_with_args(first_argument, second_argument):
print(f"{first_argument} - {second_argument}")
def my_function_using_star_args(*args):
print(' '.join([x for x in args]))
# coroutine example
def look_for(pattern):
while True:
temp = yield
if pattern in temp:
print("I found {} in {}!".format(pattern, temp))
else:
print("No {} in {}.".format(pattern, temp))
@ekozlowski
ekozlowski / chunks.py
Created March 7, 2017 04:30
chunking email data
from collections import deque
# Pull email_data.txt, and join into a big huge string of 1000 random emails.
emails = [x.strip() for x in open('email_data.txt', 'r').readlines() if x.strip()]
emails = ';'.join(emails)
print(emails)
def chunks(data, delimiter=";", width=500):
pieces = deque(data.split(delimiter))
s = ""
@ekozlowski
ekozlowski / arraypassing.ps1
Created August 19, 2016 20:46
Passing an array with Powershell
start-job -filepath myscript.ps1 -arg (,$myarr)
==============================================================================
Links for DFW Pythoneers - July 2016 Main Monthly Meeting
==============================================================================
For now, this is just a dump of my (Ed's) Chrome history. I'll wrap some more
context around this later. :-)
http://scikit-learn.org/stable/
https://web.stanford.edu/~mwaskom/software/seaborn/
class Test_ThisStuff(object):
def setup(self):
print('Setting up')
self.name = 'Ed'
self.age = 38
def teardown(self):
print('tearing down')
self.name = None
@ekozlowski
ekozlowski / json_example.py
Last active August 29, 2015 13:57
Example of serializing a list using JSON.
import os
import json
FILE_PATH = './my_data.json'
def load_my_list():
# If the file exists, open it and load our list
# from the file at FILE_PATH.
if os.path.exists(FILE_PATH):
@ekozlowski
ekozlowski / pickle_example.py
Last active August 29, 2015 13:57
Example of serializing a list using a Python pickle.
import os
import pickle
FILE_PATH = './my_data.pkl'
def load_my_list():
# If the file exists, open it and load our list
# from the file at FILE_PATH.
if os.path.exists(FILE_PATH):