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 | |
import collections | |
import concurrent.futures | |
import json | |
import os | |
import pathlib | |
import re | |
import requests |
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 bash | |
# You need to set some vars somewhere: | |
# SECURTITY_GROUP=<your_security_group_id> | |
# on mac you need to enable running the `at` command: | |
# $ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist | |
current_ip=$(curl -s http://checkip.amazonaws.com/) | |
echo "Current IP: ${current_ip}" |
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
@Service | |
@Slf4j | |
public class UserService { | |
private final ApplicationEventPublisher applicationEventPublisher; | |
private final UserRepository userRepository; | |
UserService(ApplicationEventPublisher applicationEventPublisher, | |
UserRepository userRepository) { | |
this.applicationEventPublisher = applicationEventPublisher; | |
this.userRepository = userRepository; |
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.6 | |
import asyncio | |
import aioamqp | |
async def main(loop=None): | |
if loop is None: | |
loop = asyncio.get_event_loop() | |
transport, protocol = await aioamqp.connect() | |
channel = await protocol.channel() |
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
@Service | |
public class MyWorker { | |
@RabbitListener(bindings = | |
@QueueBinding(value = @Queue( | |
value = "${spring.application.name}.worker.my_job", | |
durable = "false", | |
// ensure that the message expires in some reasonable period, | |
// a safe number is 1/2 the time between events | |
arguments = { | |
@Argument(name = "x-message-ttl", |
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
ticktock: | |
scheduler: | |
cron: | |
"0 * * * * *": "cron.minute.1" | |
"0 */5 * * * *": "cron.minute.5" | |
"0 */2 * * * *": "cron.minute.2" | |
"0 */10 * * * *": "cron.minute.10" | |
"0 */15 * * * *": "cron.minute.15" | |
"0 */30 * * * *": "cron.minute.30" | |
"0 */45 * * * *": "cron.minute.45" |
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
""" | |
Naive implementation of an iterable queue in asyncio | |
""" | |
#!/usr/bin/env python3 | |
import asyncio | |
class Queue(asyncio.Queue): | |
async def __aiter__(self): |
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 | |
async def func_two(): | |
await asyncio.sleep(2.5) | |
raise RuntimeError | |
async def func_one(): | |
try: | |
await func_two() | |
except RuntimeError as e: |
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 | |
def long_running_system_task(): | |
import time | |
print('starting background task') | |
# Normally this would block the event loop, but it's okay | |
# when called in another thread with an executor :) | |
time.sleep(3) | |
return 'finished tasks' |
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 first_async_function(): | |
yield from asyncio.sleep(2.5) | |
return 'Result found!' | |
async def new_async_function(): | |
res = await first_async_function() |