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/python | |
# First some classes to implement graph theory. These aren't supposed to know | |
# anything about Physics. | |
class Node(object): | |
"""Nodes are told about the edges that exist as they are created, so | |
they know about each other. This means that a set of connected Nodes can be | |
referred to by any one of them; none are special.""" |
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/python3 | |
# Conway's Game of Life | |
# Based on Jack Diederich's implementation | |
# http://pyvideo.org/video/880/stop-writing-classes | |
from itertools import chain, product | |
neighbour_deltas = set(list(product([-1, 0, 1], repeat=2))) - set([(0, 0)]) |
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/python3 | |
STARTING_SCORE = ('0', '0') | |
# key: previous score; value: new score if player 0 scores a point from that | |
POINT_LOOKUP = { | |
('0', '0'): ('15', '0'), | |
('0', '15'): ('15', '15'), | |
('0', '30'): ('15', '30'), | |
('0', '40'): ('15', '40'), |
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 rental_car_discount(days): | |
if days < 3: | |
return 0 | |
elif 3 <= days < 7: | |
return 20 | |
elif days >= 7: | |
return 50 | |
def rental_car_cost(days): | |
return (days * 40) - rental_car_discount(days) |
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/python3 | |
from random import choice | |
from itertools import product | |
from time import sleep | |
class GameOfLife(object): | |
def __init__(self, height, width): | |
self.size = (height, width) |
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
.align 2 | |
.thumb | |
.thumb_func | |
.type slp_switch, %function | |
slp_switch: | |
.LFB133: | |
.file 3 "platform/switch_arm32_gcc.h" | |
.loc 3 54 0 | |
.cfi_startproc | |
@ args = 0, pretend = 0, frame = 16 |
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
.align 2 | |
.thumb | |
.thumb_func | |
.type slp_switch, %function | |
slp_switch: | |
.LFB133: | |
.file 3 "platform/switch_arm32_gcc.h" | |
.loc 3 57 0 | |
.cfi_startproc | |
@ args = 0, pretend = 0, frame = 16 |
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
.align 2 | |
.thumb | |
.thumb_func | |
.type slp_switch, %function | |
slp_switch: | |
.LFB133: | |
.file 3 "platform/switch_arm32_gcc.h" | |
.loc 3 57 0 | |
.cfi_startproc | |
@ args = 0, pretend = 0, frame = 16 |
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 asyncio | |
class Worker: | |
'''A Worker has background asyncio tasks that are cancelled on __del__''' | |
def __init__(self, loop=None): | |
self._loop = loop if loop else asyncio.get_event_loop() | |
# This set serves to keep incomplete tasks alive as long as this class | |
# instance exists. | |
self._tasks = set() |
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
#!/bin/sh | |
set -e | |
# lxd-ssh | |
# Wrapper for using ssh/scp/etc with lxd | |
# Author: Robie Basak <robie.basak@canonical.com> | |
# Last-Update: 2017-10-11 | |
# Instructions: | |
# |
OlderNewer