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
""" | |
Geometric mean calculation in Python. | |
""" | |
import math | |
import operator | |
from random import randint | |
from timeit import timeit | |
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 | |
""" | |
Turn CSV input into TSV output. | |
""" | |
import csv, sys | |
for row in csv.reader(sys.stdin): | |
print("\t".join(row)) |
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
""" | |
Multiclass SVMs (Crammer-Singer formulation). | |
A pure Python re-implementation of: | |
Large-scale Multiclass Support Vector Machine Training via Euclidean Projection onto the Simplex. | |
Mathieu Blondel, Akinori Fujino, and Naonori Ueda. | |
ICPR 2014. | |
http://www.mblondel.org/publications/mblondel-icpr2014.pdf | |
""" |
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 | |
from fabric.api import local | |
def hello(name='world'): | |
print('\n\n') | |
print('Hello %s!' % name) | |
print('\n\n') |
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
def category(request, model, tag): | |
""" | |
Given a lowercase model name and tag, search for all models linked to | |
the given tag. The model is obtained by looking through a dictionary of | |
available models. | |
""" | |
available_models = {'apps': App, 'data': Data, 'ideas': Idea} | |
try: | |
actual_model = available_models[model] | |
except KeyError: |
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 | |
"""Looking up environment variables through `vars`.""" | |
def ohai(): | |
"""A simple function.""" | |
print 'ohai' | |
class Foo(object): |
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 | |
"""Looking up environment variables through `vars`.""" | |
def ohai(): | |
"""A simple function.""" | |
print 'ohai' | |
class Foo(object): |
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
"""Just showing off timeit to tell the difference between operations.""" | |
from timeit import Timer | |
# We'll run each one a thousand times. | |
print Timer("[0] * 7000").timeit(1000) | |
print Timer("bytearray(7000)").timeit(1000) | |
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 | |
"""For ctbarna.""" | |
list_of_dicts = [ | |
{'key_1': 'value_1', 'key_2': 'value_2'}, | |
{'key_1': {'inception_key': 'inception_value'}, 'key_2': 'value_2'}, | |
{'key_1': 'value_1', 'key_2': 'value_2'}, | |
] |
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 | |
"""For ctbarna.""" | |
list_of_dicts = [ | |
{'key_1': 'value_1', 'key_2': 'value_2'}, | |
{'key_1': {'inception_key': 'inception_value'}, 'key_2': 'value_2'}, | |
{'key_1': 'value_1', 'key_2': 'value_2'}, | |
] |
OlderNewer