Skip to content

Instantly share code, notes, and snippets.

import asyncio
from collections import defaultdict
from async_lru import alru_cache
num_email_confirmations = defaultdict(int)
@alru_cache(maxsize=500)
async def send_email_confirmation(user_email: str) -> int:
num_email_confirmations[user_email] += 1
#lang racket
; some examples of macros in scheme
; example from
; https://hipster.home.xs4all.nl/lib/scheme/gauche/define-syntax-primer.txt
(define-syntax nth-value
(syntax-rules ()
((nth-value n values-producing-form)
(call-with-values
@egeromin
egeromin / fully_connected_net.py
Last active January 29, 2018 16:49
Train a fully connected NN to classify MNIST digits. Implemented using numpy only.
"""
Class to define a fully connected neural net. Written using
numpy only.
The number and size of hidden layers is defined by providing
a list to the constructor, for example
```
net = FullyConnectedNet([1024, 450, 10])
```
@egeromin
egeromin / async-experiments.md
Created January 20, 2018 21:33
Asynchronous Programming and Microservices: Comparing Javascript, Erlang and Python with RabbitMQ + Celery

Asynchronous Programming and Microservices: Comparing Javascript, Erlang and Python with RabbitMQ + Celery

This article is about building asynchronous microservices. I'll compare how this can be achieved in Javascript and Erlang natively, and in Python using RabbitMQ and Celery.

But why?

My first encounter with asynchronous programming in python was when building a web backend. Upon completing a purchase, the user should eventually receive a PDF invoice by email. This didn't have to happen immediately during the request; in fact, it was better if it didn't, so as not to slow down the purchase needlessly. At the time I wasn't sure how to implement an asynchronous workflow in python, but a quick google search quickly lead me to Celery and RabbitMQ. Celery is very easy to use; the only pain is setting up a message broker -- RabbitMQ, in my case. Once you're set up, running a task in the background is as easy as writing, in myapp.py,