Skip to content

Instantly share code, notes, and snippets.

View sxslex's full-sized avatar

Alexandre Villela - SleX sxslex

View GitHub Profile
@sxslex
sxslex / client.py
Created May 8, 2017 18:20
custom client.py for redis
from __future__ import with_statement
from itertools import chain
import datetime
import sys
import warnings
import time
import logging
import threading
import time as mod_time
from redis._compat import (b, basestring, bytes, imap, iteritems, iterkeys,
@sxslex
sxslex / decompor_decimal.py
Last active May 24, 2017 20:35
Decompoe um numero em sua representação decimal
# -*- coding: utf-8 -*-
def decompor_decimal(num):
"""Decompoe um numero em sua representação decimal. """
l = len(str(num))
return ' + '.join([i.ljust(l - b, '0') for b, i in enumerate(str(num))])
print(decompor_decimal(32477))
@sxslex
sxslex / troco.py
Last active January 29, 2018 16:46
Troco
# -*- coding: utf-8 -*-
def notas_total(valor):
notas = [100, 50, 20, 10, 5, 2, 1]
totais = []
for idx, nota in enumerate(notas):
totais.append(0)
if valor > nota:
totais[idx] = int(valor / nota)
valor -= totais[idx] * nota
@sxslex
sxslex / partition.py
Created May 25, 2017 17:24
Elegant Python code for Integer Partitioning
# -*- coding: utf-8 -*-
import timeit
ncache = 0
cache = {}
def partition(number):
global cache, ncache
answer = {(number,), }
@sxslex
sxslex / noticias.js
Created July 5, 2017 16:26
noticias
var noticias = {"ultimas": {"noticia/tecnologia": [{"pasta": "Noticia/Tecnologia", "imagem_330x220": "https://i.em.com.br/21JEkvZUvC5jrl0EdfTFTPe8cic=/330x220/smart/imgsapp.em.com.br/app/noticia_127983242361/2017/06/14/876552/20170614200611475069i.jpg", "imagem": "http://imgsapp.em.com.br/app/noticia_127983242361/2017/06/14/876552/20170614200611475069i.jpg", "url": "http://www.em.com.br/app/noticia/tecnologia/2017/06/14/interna_tecnologia,876552/netflix-supera-tvs-a-cabo-em-numero-de-assinantes-nos-estados-unidos.shtml", "titulo": "Netflix supera TVs a cabo em n\u00famero de assinantes nos Estados Unidos", "data": "19:56 14/06/2017", "descricao": "Servi\u00e7o de streaming de v\u00eddeos teve crescimento de 5,4 milh\u00f5es de assinantes por ano nos \u00faltimos cinco anos"}, {"pasta": "Noticia/Tecnologia", "imagem_330x220": "https://i.em.com.br/Ku6jryC0cpHHHoWwg-ivIaP6MhA=/330x220/smart/imgsapp.em.com.br/app/noticia_127983242361/2017/03/27/857434/20170327102023584363e.jpg", "imagem": "http://imgsapp.em.com.b
@sxslex
sxslex / assert_rotation_image.py
Last active November 9, 2017 15:32
assert_rotation_image
# -*- coding: latin1 -*-
"""
Codigo para colocar uma imagem na orientacao correta.
"""
from PIL import Image
from PIL.ExifTags import TAGS
def get_exif(img):
info_exif = {}
@sxslex
sxslex / urionlinejudg_problem_1566.c
Created November 12, 2017 02:13
urionlinejudg problem 1566
// https://www.urionlinejudge.com.br/judge/en/problems/view/1566
include <stdio.h>
#include <stdlib.h>
struct Node{
int num;
struct Node *prox;
};
typedef struct Node node;
@sxslex
sxslex / meta_programacao.py
Created November 24, 2017 19:41
meta programacao
class MyClass(object):
"""Legal."""
def __init__(self, **kwargs):
object.__init__(self)
self._session = dict(**kwargs)
self._session['idade'] = 98
self._a_salvar = []
@sxslex
sxslex / postgis_example.sql
Last active February 27, 2018 16:17
PostGis - Cadastrando áreas e buscando a área que atende a coordenada
-- http://www.gmapas.com/poligonos-ibge/municipios-do-brasil
-- Download do arquivo KML com 5.566 municípios brasileiros
-- https://docs.google.com/a/gmapas.com/file/d/0B2yOq3AMumqRM2Q0cXVETVJvb1U/edit
CREATE EXTENSION postgis;
CREATE TABLE cidades (
id SERIAL PRIMARY KEY,
cidade VARCHAR(64),
estado VARCHAR(2),
polygon GEOMETRY
@sxslex
sxslex / script_semaphore.sh
Created March 28, 2018 17:31
script bash para controle de execução através de semaforo.
#!/bin/bash
# Deve ser executado de 15 em 15 minutos
# CRONTAB
# 0 15,30,45 * * * * script_semaphore.sh > script_semaphore.log 2>&1
echo $(date)
DIR=$(dirname $0)
PIDFILE=${DIR}"/script_semaphore.pid"
PUBLICA=$(dirname $(dirname $(dirname $DIR)))