Skip to content

Instantly share code, notes, and snippets.

View jonathaneunice's full-sized avatar

Jonathan Eunice jonathaneunice

View GitHub Profile
@jonathaneunice
jonathaneunice / gist:30e21cffa3b3e7b61952
Last active August 29, 2015 14:06
Demonstration of an "overwriteable file proxy."
"""
Demonstration of an "overwriteable file proxy." It appears you are
reading from, processing, and updating a file. In reality, writes are
driven to a temporary file which is then renamed to the 'original'
name. `OverWriter` proxies can be used stand-alone, or as a context
manager in a `with` statement.
"""
import re
import os
import benchmark
s = '16122.83'
class Options(benchmark.Benchmark):
each = 1000
@jonathaneunice
jonathaneunice / gist:0b2a5892ce2eaa834a91
Created October 21, 2014 17:46
Capture stdout and stderr conveniently from within Python programs
import contextlib
import sys
from StringIO import StringIO
# Output capturing helpers thanks to
# test.test_support and http://stackoverflow.com/a/18844643/240490
# extended by Jonathan Eunice to add easy saving to a file (including
# auto-save if a filepath is provided in the constructor)
# This is not quite polished enough to make it into a full PyPI
from random import choice, randint
import string
import time
import sys
_PY3 = sys.version_info[0] == 3

Dirty Data Still Dirty
Sad Panda Still Sad

The New York Stock Exchange (NYSE) historical records contain multiple, absurdly novice errors. It's dirty data, referring to days that don't exist, and giving multiple inconsistent answers for over a month of trading days. And this is the data set of record, from the world's leading financial

from itertools import *
def groups_of_n(iterable, n):
"""
Collect data into fixed-length chunks or blocks. Generates (yields)
a sequence of iterators. Useful for segmenting very large sequences
into more manageable chunks. If the final chunk is of less than size n,
no worries. It will return what there is. NB This is *much* more
/**
* CSS imperative declarations.
* E.g. cssi('div#one.two.three')
* yields { element: 'div',
* id: 'one',
* class: 'two three',
* }
* Classes are not split out into an array
@jonathaneunice
jonathaneunice / headstart.md
Last active June 21, 2017 01:02
Head Start

Accelerating Problem Resolution

To speed things along, drop me

  1. an example of the data or code you're having trouble with,
  2. a short explanation of what's not working the way you want.

You can get files to me via:

@jonathaneunice
jonathaneunice / mentor-promo.md
Created August 13, 2017 15:48
Mentoring Promo

And now some obligatory self-promotion:

I've completed over 350 successful Codementor sessions, with [top-notch reviews][1].

I've contributed to the core Python project (CPython), have many published Python modules, and have completed many Python challenge problems at sites like HackerRank:

@jonathaneunice
jonathaneunice / typing_example.py
Created December 28, 2017 21:16
Typing Example
from typing import Dict, List, Union
ValueType = Union[str, int, List[str]]
order_data: Dict[str, ValueType] = {
'one': 1,
'two': 'two',
'many': ['this', 'is', 'many', 'strings'],
'keywords': ["test_1", "test_2"]
}