Skip to content

Instantly share code, notes, and snippets.

Avatar

Diego Garcia drgarcia1986

View GitHub Profile
@drgarcia1986
drgarcia1986 / Vagrantfile
Last active Jun 22, 2019
Hello World with Ansible and Vagrant
View Vagrantfile
# 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 Aug 3, 2015
Escape from GIL's block in intensive CPU tasks with ProcessPoolExecutor (web example)
View app.py
import concurrent.futures
import muffin
app = muffin.Application(
'process_executor'
)
@drgarcia1986
drgarcia1986 / blocking_to_async.py
Last active Nov 13, 2016
Calling a blocking task asynchronously in Tornado with ThreadPoolExecutor
View blocking_to_async.py
# -*- 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 Aug 7, 2021
Tornado and Asyncio Mixed example
View tornado_asyncio.py
# -*- 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 Jun 30, 2015
Cotação do dólar baseada no site http://dolarhoje.com/
View dolar_hoje.py
# -*- 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 Jun 29, 2015
Escolas, em funcionamento, sem água, energia e esgoto, mostrando alguns detalhes (versão asyncio) (baseado em https://gist.github.com/fmasanori/4d6b7ea38a28681a513a)
View schools_async.py
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
Collection of CodinGame puzzles solved (http://www.codingame.com/)
View onboarding.py
# 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 Aug 29, 2015
Stop and remove all Docker containers and images
View remove.sh
# 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 Jul 19, 2021
Python HelloWorld (WebFrameworks) Collection
View bottle_hello.py
# -*- 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 Jan 18, 2015
Add Git Branch Name to Terminal Prompt (ubuntu)
View .bash_aliases
# 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)$: