Skip to content

Instantly share code, notes, and snippets.

Avatar

Diego Garcia drgarcia1986

View GitHub Profile
@drgarcia1986
drgarcia1986 / hello.py
Created Sep 25, 2018
simple python built-in web hello world
View hello.py
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 Jun 5, 2018
Trie Data Structure
View output
KEY: b
-KEY: o
--KEY: b
KEY: c
-KEY: a
--KEY: r
-KEY: u
--KEY: t
---KEY: e
KEY: t
View logger.go
package logger
import (
"bytes"
"io"
"log"
)
type FilteredWriter struct {
io.Writer
@drgarcia1986
drgarcia1986 / main.go
Created May 25, 2017
Ultra simple Golang Reflection example
View main.go
package main
import (
"fmt"
"reflect"
)
type sA struct {
foo int
bar string
@drgarcia1986
drgarcia1986 / type.go
Last active Dec 22, 2017
Golang Error Handling examples
View type.go
// 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 Aug 25, 2016
Link redirect and click counter in Go
View main.go
package main
import (
"fmt"
"net/http"
)
type RedirectHandler struct {
Counter chan string
}
View primes_numbers.py
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):
View multi_requests.py
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
asyncio/muffin/aiohttp examples
View muffin_blocking_to_async_process.py
from concurrent.futures import ProcessPoolExecutor
import time
import muffin
app = muffin.Application('hello_world')
def get_msg():
@drgarcia1986
drgarcia1986 / wait_example.py
Created Aug 15, 2015
Python asyncio.wait example with identified futures.
View wait_example.py
import asyncio
import aiohttp
URL_LIST = [
'http://google.com',
'http://abc.xyz',
'http://github.com',
'https://www.python.org/'