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 digit(num, n): | |
"""Returns nth digit of num (both integers)""" | |
return abs(num)//10**n%10 |
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
$ go get -u github.com/username/repo | |
# Profile test | |
$ go test -coverprofile cover.out github.com/username/repo | |
# Generate nicer html representation from profiles | |
$ go tool cover -html=cover.out -o cover.html |
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
# For more details: http://matthiaseisen.com/pp/patterns/p0203/ | |
for index, abin in enumerate(packer): | |
bw, bh = abin.width, abin.height | |
print('bin', bw, bh, "nr of rectangles in bin", len(abin)) | |
fig = plt.figure() | |
ax = fig.add_subplot(111, aspect='equal') | |
for rect in abin: | |
x, y, w, h = rect.x, rect.y, rect.width, rect.height | |
plt.axis([0,bw,0,bh]) |
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 operator import attrgetter | |
def sort_by_attr(alist, *args): | |
""" | |
Sort an object list by one or more of its atributes | |
Parameters: | |
alist (list): object list | |
*args (strings): the name of one or more of the objects attributes | |
possibly preceded by a '-' sign to use reversed order |