Skip to content

Instantly share code, notes, and snippets.

@drgarcia1986
drgarcia1986 / udp_client.py
Created February 17, 2014 23:51
Classe feita em Python que encapsula um cliente UDP enviando e recebendo mensagens de um servidor.
__author__ = 'diego.garcia'
import socket
class UDPClient:
__IP = '255.255.255.255'
__PORT = 49152
__udp_cli = ''
@drgarcia1986
drgarcia1986 / Singleton.Example.pas
Created February 25, 2014 18:18
Esqueleto para criação de uma classe Singleton em Delphi
unit Singleton.Example;
interface
type
TMyClass = class
strict private
class var FInstance : TMyClass;
private
class procedure ReleaseInstance();
@drgarcia1986
drgarcia1986 / hello.py
Created September 25, 2018 17:53
simple python built-in web hello world
from http.server import BaseHTTPRequestHandler, HTTPServer
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200, 'OK')
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(b'{"message": "hello world"}')
@drgarcia1986
drgarcia1986 / output
Created June 5, 2018 02:18
Trie Data Structure
KEY: b
-KEY: o
--KEY: b
KEY: c
-KEY: a
--KEY: r
-KEY: u
--KEY: t
---KEY: e
KEY: t
@drgarcia1986
drgarcia1986 / muffin_blocking_to_async_process.py
Last active May 21, 2018 06:53
asyncio/muffin/aiohttp examples
from concurrent.futures import ProcessPoolExecutor
import time
import muffin
app = muffin.Application('hello_world')
def get_msg():
@drgarcia1986
drgarcia1986 / type.go
Last active December 22, 2017 20:10
Golang Error Handling examples
// By Type
// Go playground https://play.golang.org/p/lJOCJAq8WL
package main
import "fmt"
type ErrorX struct{}
func (e *ErrorX) Error() string {
return "It's error X"
@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&'
package logger
import (
"bytes"
"io"
"log"
)
type FilteredWriter struct {
io.Writer
@drgarcia1986
drgarcia1986 / wait_example.py
Created August 15, 2015 02:57
Python asyncio.wait example with identified futures.
import asyncio
import aiohttp
URL_LIST = [
'http://google.com',
'http://abc.xyz',
'http://github.com',
'https://www.python.org/'
from concurrent.futures import as_completed, ThreadPoolExecutor
from urllib.request import urlopen
import re
import sys
DEFAULT_REGEX = r'<input type="text" id="nacional" value="([^"]+)"/>'
CURRENCY = {
'dolar': 'http://dolarhoje.com/',
'euro': 'http://eurohoje.com/',