Skip to content

Instantly share code, notes, and snippets.

View mittmannv8's full-sized avatar

Cleiton Junior Mittmann mittmannv8

  • AvenueCode [https://www.avenuecode.com/]
  • Lisbon, Portugal
View GitHub Profile
@mittmannv8
mittmannv8 / strategy_best.py
Created May 15, 2015 05:19
Excercício ppqsp8: Criar um decorator que carregue automaticamente todas as promoções
# strategy_best.py
# Strategy pattern -- function-based implementation
# selecting best promotion from static list of functions
"""
>>> joe = Customer('John Doe', 0)
>>> ann = Customer('Ann Smith', 1100)
>>> cart = [LineItem('banana', 4, .5),
... LineItem('apple', 10, 1.5),
... LineItem('watermellon', 5, 5.0)]
@mittmannv8
mittmannv8 / promocoes.py
Last active August 29, 2015 14:21
Excercício ppqsp8: Criar um decorator que carregue automaticamente todas as promoções
from utils import promo
@promo
def fidelity_promo(order):
"""5% discount for customers with 1000 or more fidelity points"""
return order.total() * .05 if order.customer.fidelity >= 1000 else 0
@promo
@mittmannv8
mittmannv8 / bin_string.py
Created September 14, 2015 19:51
Convert string to bin and reverse
import binascii
# Bin to string
def tostring(b):
b = int(b, 2)
return binascii.unhexlify('%x' % b)
# String to bin
def tobin(s):
return bin(int(binascii.hexlify(s), 16))
<!DOCTYPE html>
<html>
<head>
<title>React.js learn</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
@mittmannv8
mittmannv8 / python_cgi_restful.md
Created April 9, 2017 17:49
Exemple for apply restful routes in Python CGI with Nginx.

Snippet to apply Restful routes in Python CGI

Setting endpoint at nginx using regex

The syntax bellow match any route beginning with / api / and followed by any word and a iso format date, like /api/category/1999-01-01/

location ^~ /api/(\w+)/(\d{4}-\d{2}-\d{2})/$ {
   # Settings to Python CGI file
}
@mittmannv8
mittmannv8 / wordcount.py
Last active April 21, 2020 00:47
Desafio Refatoração na prática - Henrique Bastos
"""
13. wordcount
Este desafio é um programa que conta palavras de um arquivo qualquer de duas
formas diferentes.
A. Lista todas as palavras por ordem alfabética indicando suas ocorrências.
Ou seja...
@mittmannv8
mittmannv8 / README.md
Created May 1, 2020 19:30
Script to get images from images.google.com

Get images from Google images

Search on Google the images dataset as you wish, copy the url and run the script as:

python get_images.py <path where images will be saved> <url copied from Google>
@mittmannv8
mittmannv8 / gist:45572eb91d936bb269e32180cfee5086
Last active May 20, 2020 16:22
threading_experiments.py
import time
import random
from concurrent.futures import ThreadPoolExecutor
import timeit
def fn(n):
print(n)
@mittmannv8
mittmannv8 / loading.py
Last active February 17, 2024 11:48
Animated loading context
from threading import Thread, Event
from itertools import cycle
class Loading:
"""
Shows an animated loading message on screen while some long process is processing.
Args:
message(str): message
import socket
from queue import Queue, Empty
from random import randint
from threading import Event, get_ident, Thread
class QueuedThreadProcess(Thread):
def __init__(self, queue, stop_event):
super().__init__()
self._queue = queue