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
""" | |
Proof of concept | |
Someone wanted to parse number from random strings and sum them as part of some school project. | |
@author: Matthew Purdon | |
""" | |
from __future__ import print_function | |
import sys |
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
""" | |
Proof of concept | |
Returning a tuple is nice in python but it would be better if we could return | |
an object that was truthy when compared and stringy when cast as a string | |
@author Matthew Purdon | |
""" | |
from collections import namedtuple |
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
""" | |
Proof of Concept | |
Following the course of an exception in a class hierarchy similar to that | |
in Django views. | |
@author Matthew Purdon | |
""" |
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 importlib | |
mod = importlib.import_module('dir.mymodule') | |
MyClass = getattr(mod, 'MyClass') | |
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
if __name__ == '__main__': | |
numbers = [1, 3, 5, 15, 17, 99, 100, 210, 217] | |
for number in numbers: | |
print 'Bizz'*(number%3==0) + 'Fuzz'*(number%5==0) or number | |
print '--' | |
BIZZ_FUZZ = {3: 'Bizz', 5: 'Fuzz'} | |
for number in numbers: |
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
#!/usr/bin/env python | |
""" | |
Does a quick scan of the current subnet for the specified IP range and ports | |
- Used to find a listening chromecast | |
""" | |
import threading | |
import time |
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
""" | |
String reversal Algorithm | |
Technically we would do 'something'[::-1] to reverse a string but | |
as an excercise I did it myself without using additional memory. | |
This is technically a lie since strings are immutable in python but | |
it gives you the idea... | |
""" |
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
# -*- coding: utf-8 -*- | |
""" | |
Normally we call a function like so: | |
some_function(key=value) | |
But what if we want to dynamically set a key and value from variables? | |
What if we want the function to expect a variable number of kwargs? | |
""" |
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
# -*- coding: utf-8 -*- | |
""" | |
There are a few algorithms for determining collinearity, | |
since we are in two dimensional space with limited neighbours | |
we can afford to use the simpler first difference one. | |
""" | |
from __future__ import print_function | |
from operator import itemgetter |
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 time | |
from datetime import datetime | |
def check_sleep(amount): | |
start = datetime.now() | |
time.sleep(amount) | |
end = datetime.now() | |
delta = end-start | |
return delta.seconds + delta.microseconds/1000000. |
OlderNewer