Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 | |
import functools | |
import types | |
def my_coroutine(func): | |
@functools.wraps(func) | |
def wrapper(*args, **kwargs): | |
result_fut = asyncio.Future() |
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 twisted.internet import defer | |
from asyncio import futures, get_event_loop | |
d = defer.Deferred() | |
d.addCallback(lambda x: x + 1) | |
d.addCallback(lambda x: x * 2) | |
f1 = futures.Future() | |
f2 = futures.Future() | |
f1.add_done_callback(lambda f: f2.set_result(f.result() + 1)) |
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 | |
import aiohttp | |
from aiohttp import web | |
class WebsocketProxy(object): | |
def __init__(self, upstream_url): | |
self.upstream_url = upstream_url |
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 concurrent.futures import Future | |
fut = Future() | |
fut.add_done_callback(lambda f: f.result() * 2) | |
fut.set_result(21) | |
print(fut.result()) | |
#assert fut.result() == 42 | |
fut = Future() |
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
'''library to support calling asyncio functions from synchronous code | |
''' | |
import asyncio | |
import functools | |
import queue | |
import threading | |
def create_and_start_loop(): | |
loop = asyncio.new_event_loop() |
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
var fs = require('fs'); | |
for (i=0; i<10000; i++) { | |
fs.writeSync(process.stdout.fd, 'hello world!\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
import t | |
t.hello | |
import jedi | |
script = jedi.Script(path=__file__, line=2, column=7) | |
definition = script.goto_definitions()[0] | |
print(repr(definition.docstring())) |
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 string, sys | |
t = str.maketrans(string.ascii_uppercase+string.ascii_lowercase, | |
''.join(chr(u) for u in range(0x1d4d0, 0x1d504))) | |
print(sys.stdin.read().translate(t)) |
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
'''Niconico Style Display | |
requirements: | |
PyQt5 | |
pyobjc-framework-Cocoa (pyobjc-cocoa?, osx only) | |
''' | |
import multiprocessing | |
import sys | |
import threading |