Skip to content

Instantly share code, notes, and snippets.

View strikaco's full-sized avatar
💋
Chaotic Good

Johnny strikaco

💋
Chaotic Good
View GitHub Profile
@strikaco
strikaco / JsonHandler.py
Created October 12, 2017 16:52
Django Model JsonHandler
class JsonHandler(object):
"""
Handles serialization/deserialization of attributes in the JSON blob.
Requires a field of type TextField named 'blob' on the source model.
These are not searchable unless you do FTS on the obj.blob field!
"""
def __init__(self, node, *args, **kwargs):
# Must set via dict interface or else it triggers __setattr__
@strikaco
strikaco / search.py
Last active January 21, 2017 12:08
Alternate implementation of NLTK's concordance() - no dependencies needed!
def concordance(string, search_term, width=25):
"""
Alternative implementation of NLTK's concordance() that
allows printing to stdout or saving to a variable and
does not require NLTK.
Just feed it a raw string, JSON string, etc. with any line
breaks stripped out.
"""
# Offset tracks our progress as we parse through the string
@strikaco
strikaco / iotest.py
Created January 16, 2017 04:38
Python - Are Threads or Processes more appropriate for disk I/O-bound operations?
from threading import Thread
from multiprocessing import Process
from os import remove
from time import time
class IOTest:
max_workers = 10
max_lines = 10000000