Skip to content

Instantly share code, notes, and snippets.

@drgarcia1986
drgarcia1986 / main.go
Created May 25, 2017 18:55
Ultra simple Golang Reflection example
package main
import (
"fmt"
"reflect"
)
type sA struct {
foo int
bar string
@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 / main.go
Last active August 25, 2016 10:25
Link redirect and click counter in Go
package main
import (
"fmt"
"net/http"
)
type RedirectHandler struct {
Counter chan string
}
from concurrent.futures import ProcessPoolExecutor, as_completed
import sys
TO_CALCULATE = range(1000, 15000, 1000)
def primes_until(num):
result = []
for p in range(2, num+1):
@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 / 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 / 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 / .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)$:
@drgarcia1986
drgarcia1986 / __main__.py
Created January 2, 2015 05:20
Facebook "Liker"
import logging
import json
import urllib3
import sys
class Liker():
__URL_API = 'https://graph.facebook.com/v2.2'
__URL_ME = '/me?fields=id'
__URL_HOME = '/me/home?fields=from,likes'