Skip to content

Instantly share code, notes, and snippets.

@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
package logger
import (
"bytes"
"io"
"log"
)
type FilteredWriter struct {
io.Writer
@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 / 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 / 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):
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/',
@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 / 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/'