This file contains hidden or 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
# Try appending ?ts=2 to the url of this page. | |
# Then try ?ts=4 | |
# Then ?ts=8 | |
def my_member_function(self, argument): | |
for value in range(10): | |
# Notice how, as the indents shift, all the arguments | |
# to this function stay vertically aligned. | |
self.my_other_func(argument, | |
value, |
This file contains hidden or 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
class SyncClientThread: | |
def __init__(self): | |
... | |
self.stop = False | |
self.nostop_depth = 0 | |
def Stop(self): | |
self.stop = True | |
def IsStopped(self): | |
return self.nostop_depth == 0 and self.stop |
This file contains hidden or 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 emit(list_of_elements): | |
for elem in list_of_elements: | |
if elem.thing1 > 0: | |
yield elem.thing1 | |
if elem.thing2 < 0: | |
yield elem.thing2 | |
if elem.thing3 != 0: | |
yield elem.thing3 |
This file contains hidden or 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
//Global Data example | |
function load_problem(tokens) { | |
global_data = get_global_data(tokens) | |
return global_data.num_cases, function(tokens) { | |
case_specific_data = get_case_data(tokens) | |
return function() { | |
// Do a bunch of math with global_data and case_specific_data | |
return solution | |
} | |
} |
This file contains hidden or 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 | |
@asyncio.coroutine | |
def scan_remote(host, port, timeout=1): | |
try: | |
connection = asyncio.open_connection(host, port) | |
yield from asyncio.wait_for(connection, timeout) | |
except (OSError, asyncio.TimeoutError): | |
pass | |
else: |
This file contains hidden or 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 __future__ import print_function, unicode_literals | |
from tempfile import SpooledTemporaryFile as TempFile | |
from shutil import copyfileobj | |
from argparse import ArgumentParser | |
from io import open | |
def trim_white(istr): |
This file contains hidden or 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 exporter(all): | |
def export(thing): | |
all.append(thing.__name__) | |
return thing | |
return export | |
################################### | |
__all__ = [] |
This file contains hidden or 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 tkinter import * | |
import asyncio | |
from functools import wraps | |
import websockets | |
def runloop(func): | |
''' | |
This decorator converts a coroutine into a function which, when called, | |
runs the underlying coroutine to completion in the asyncio event loop. | |
''' |
This file contains hidden or 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
class FunctionNotFoundError(KeyError): | |
pass | |
class Registry: | |
def __init__(self): | |
self.registry = {} | |
def register(self, key): | |
def decorator(func): | |
self.registry[key] = func |
This file contains hidden or 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 python3 | |
# Copyright 2015 Nathan West | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, |