View fractional_powers.py
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
from fractions import gcd | |
from functools import reduce | |
import numpy | |
def lcm(a, b): | |
"""Return the least common denominator of two non-negative numbers.""" | |
return a*b//gcd(a, b) |
View closest_index_in_range.py
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 closest_index_in_range(lower, upper, step, value): | |
''' | |
Find the index of the closest value to `value` in the range | |
[lower, lower + step, ..., upper - step, upper] in constant time. `upper` | |
must be greater than `lower`. If `value` is outside the range, return the | |
corresponding boundary index (0 or the last index). When two values are | |
equally close, the index of the smaller is returned. | |
For example, `closest_index_in_range(-5, 5, 0.5, -4.8)` will return 0, since | |
-4.8 is closest to -5. |
View matching_colours.py
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 | |
# Copyright 2015 Eviatar Bach, eviatarbach@gmail.com | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software |
View takuzu.py
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 | |
# Copyright 2013 Eviatar Bach, eviatarbach@gmail.com | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software |
View flickr_exif.py
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 | |
import urllib | |
import os | |
import argparse | |
import flickrapi | |
api_key = '367aed513876077c1cdcadb29d88ef02' | |
api_secret = '9b6e223653519900' |
View tretyakov.py
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 | |
import urllib | |
import sys | |
import re | |
import os | |
url = 'http://www.tretyakovgallery.ru/ajax/?action=fetch_image&id=%s' % sys.argv[1] | |
url_finder = re.compile("\['src'\] = '(.+?\.jpg)'") | |
images = urllib.urlopen(url).read() |