Skip to content

Instantly share code, notes, and snippets.

@drgarcia1986
drgarcia1986 / Vagrantfile
Last active June 22, 2019 13:25
Hello World with Ansible and Vagrant
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 8000, host: 8000
config.vm.provision :ansible do |ansible|
@drgarcia1986
drgarcia1986 / app.py
Created August 3, 2015 03:17
Escape from GIL's block in intensive CPU tasks with ProcessPoolExecutor (web example)
import concurrent.futures
import muffin
app = muffin.Application(
'process_executor'
)
@drgarcia1986
drgarcia1986 / blocking_to_async.py
Last active November 13, 2016 15:24
Calling a blocking task asynchronously in Tornado with ThreadPoolExecutor
# -*- coding: utf-8 -*-
import time
import concurrent.futures
import tornado.web
import tornado.gen
import tornado.httpserver
import tornado.ioloop
@drgarcia1986
drgarcia1986 / tornado_asyncio.py
Last active August 7, 2021 15:57
Tornado and Asyncio Mixed example
# -*- coding: utf-8 -*-
import asyncio
import re
import asyncio_redis
import tornado.concurrent
import tornado.httpclient
import tornado.web
import tornado.platform.asyncio
@drgarcia1986
drgarcia1986 / dolar_hoje.py
Created June 30, 2015 16:36
Cotação do dólar baseada no site http://dolarhoje.com/
# -*- coding: utf-8 -*-
import urllib.request
import re
resp = urllib.request.urlopen('http://dolarhoje.com/').read()
resp = resp.decode('utf-8')
dolar = re.search(
r'<input type="text" id="nacional" value="(?P<dolar>[^"]+)"/>', resp
)
@drgarcia1986
drgarcia1986 / schools_async.py
Created June 29, 2015 21:59
Escolas, em funcionamento, sem água, energia e esgoto, mostrando alguns detalhes (versão asyncio) (baseado em https://gist.github.com/fmasanori/4d6b7ea38a28681a513a)
import asyncio
import json
import aiohttp
SCHOOL_URL_FMT = 'http://educacao.dadosabertosbr.com/api/escola/{}'
SEARCH_SCHOOL_URL = (
'http://educacao.dadosabertosbr.com/api/escolas/buscaavancada?'
'situacaoFuncionamento=1&energiaInexistente=on&aguaInexistente=on&'
@drgarcia1986
drgarcia1986 / onboarding.py
Created May 10, 2015 23:01
Collection of CodinGame puzzles solved (http://www.codingame.com/)
# game loop
while 1:
enemy1, dist1 = input(), int(input())
enemy2, dist2 = input(), int(input())
print(enemy1) if dist1 < dist2 else print(enemy2)
@drgarcia1986
drgarcia1986 / remove.sh
Last active August 29, 2015 14:15
Stop and remove all Docker containers and images
# Stop all docker containers
sudo docker stop $(sudo docker ps -a -q)
# Delete all docker containers
sudo docker rm -f $(sudo docker ps -a -q)
# Delete all docker images
sudo docker rmi -f $(sudo docker images -q)
@drgarcia1986
drgarcia1986 / bottle_hello.py
Last active September 30, 2022 16:19
Python HelloWorld (WebFrameworks) Collection
# -*- coding: utf-8 -*-
from bottle import route, run
@route('/')
def index():
return '<h1>Hello World/h1>'
run(host='localhost', port=8000)
@drgarcia1986
drgarcia1986 / .bash_aliases
Created January 18, 2015 13:24
Add Git Branch Name to Terminal Prompt (ubuntu)
# Import Git script for PS1
source /etc/bash_completion.d/git-prompt
# Color definition for PS1
txtred='\e[0;31m'
txtwhite='\e[0;37m'
txtyellow='\e[0;33m'
# Defnite PS1 in this format:
# user:dir (git branch)$: