Skip to content

Instantly share code, notes, and snippets.

View fabiocerqueira's full-sized avatar

Fabio Cerqueira fabiocerqueira

View GitHub Profile
import asyncio
import random
async def slow_action():
await asyncio.sleep(random.randrange(1, 5))
async def my_range(n):
i = 0
while i < n:
from types import coroutine
@coroutine
def spam():
result = yield 'somevalue'
print("Got it:", result)
async def foo():
@fabiocerqueira
fabiocerqueira / app.py
Last active December 11, 2016 23:24
Simple CORS with Bottle
from bottle import Bottle, response
app = Bottle()
@app.hook('after_request')
def enable_cors():
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'PUT, GET, POST, DELETE, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'

Keybase proof

I hereby claim:

  • I am fabiocerqueira on github.
  • I am fabiocerqueira (https://keybase.io/fabiocerqueira) on keybase.
  • I have a public key whose fingerprint is 18DC 7FE9 39AC F6EA E0B6 897B 0713 92F3 A0EC 8E06

To claim this, I am signing this object:

@fabiocerqueira
fabiocerqueira / spam.rb
Created July 6, 2015 16:00
Ruby whitespace sensitivity
foo = 23
def bar
42
end
puts bar /foo
-r requirements_base.txt
psycopg2==2.6.1
def int2list(n):
out = []
while n:
n, r = divmod(n, 10)
out.insert(0, r)
return out
@fabiocerqueira
fabiocerqueira / robolang.py
Last active August 29, 2015 14:11
An example of how to make a parsing with rply
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import warnings
from rply import ParserGenerator, LexerGenerator, ParsingError
from rply.lexer import LexingError
from rply.token import BaseBox
lg = LexerGenerator()
@fabiocerqueira
fabiocerqueira / robolang.py
Created December 16, 2014 06:07
An example of how to make a parsing with pyparsing
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pyparsing import (Keyword, Word, OneOrMore, Optional, CaselessLiteral,
LineEnd, Group, nums)
def robolang():
andar_token = Keyword("andar", caseless=True)
girar_token = Keyword("girar", caseless=True)
@fabiocerqueira
fabiocerqueira / plot_example.py
Created December 5, 2014 21:58
Examplo de plot
"""
Demo of the fill function with a few features.
In addition to the basic fill plot, this demo shows a few optional features:
* Multiple curves with a single command.
* Setting the fill color.
* Setting the opacity (alpha value).
"""
import numpy as np