This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace and compile | |
java source named "Hashador" as | |
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
public class Hashador{ | |
private static String stringHexa(byte[] bytes) { | |
String s =""; | |
//original com StringBuilder, mas o Oracle nao aceitou |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"A Book on C" de Al Kelley e Ira Pohl para uma introdução. | |
http://pixhost.me/avaxhome/65/a2/0016a265_medium.jpeg | |
Depois da introdução o caminho natural é ver tópicos com mais aplicações e desenvolver uma base em estrutura de dados. Gosto particularmente do Programming Abstractions in C: A Second Course in Computer Science do Eric Roberts. | |
http://i.imgur.com/z190M.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _limpa_html(self, html_bruto): | |
''' | |
Processa o html recuperado e devolve apenas a lista de tags | |
definidas abaixo. | |
Dica encontrada em: | |
http://stackoverflow.com/questions/699468/python-html\ | |
-sanitizer-scrubber-filter | |
peguei uma das ideias da thread, a mais simples... | |
''' | |
TAG_VALIDAS = ['table', 'tr', 'td', 'span', 'div'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#_*_ coding: utf-8 _*_ | |
''' | |
teste simples levando em conta arquivo.txt = | |
hardwareisa => x86_64 | |
hardwaremodel => x86_64 | |
hostname => lost | |
id => gustavo | |
interfaces => eth0,lo,wlan0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tibia - graphical Multi-User-Dungeon | |
# DO NOT EDIT THIS FILE | |
Version = 1041 | |
Engine = 2 | |
FullscreenMode = (640,480,32) | |
BasicBrightness = 128 | |
WindowsMousepointer = yes | |
LightEffects = yes | |
TextualEffects = yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Eu estou utilizando mongoengine | |
''' | |
from package import models #meus documents... | |
''' | |
Exemplo: No meu models.py eu tenho um document Person | |
class Person(db.Document): | |
name = db.StringField() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Para testar um comando, função, whatever...é bem comum utilizarmos o terminal | |
do python. E para melhorar o retorno ao consultar uma lista, tupla, dicionário e etc, existe | |
o pprint. | |
Situação: Eu ainda não conheço bem os atributos de uma classe e nessa situação, eu gosto de usar a função dir(). | |
Abaixo o resultado no terminal com e sem o pprint | |
''' | |
>>> foo = dict() | |
>>> dir(foo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Usando o mongoengine, eu tenho alguns documentos no meu models.py que contém referencefield...é um recurso bem útil, | |
mas ao buscar os objetos desse documento, nesse campo eu tenho apenas o ObjectId, ou seja, o driver não faz uma busca no estilo | |
cascata. A ideia foi escrever um algoritmo simples (talvez não muito pythonico) para identificar reference fields e | |
recuperar os dados. | |
''' | |
#Um exemplo simples para models.py | |
from app import db #db = MongoEngine() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Usando mongoengine... | |
def dbref_to_objid(document): | |
''' | |
Recebe um documento como parametro e converte os DBRefs para | |
ObjectId. | |
''' | |
from bson import DBRef | |
doc_copy = document._data.copy() | |
for key, field in document._data.items(): | |
if isinstance(field, DBRef): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bin2dec(num): | |
''' | |
Exemplo simples para converter um binário para decimal | |
''' | |
return sum([int(bit)*2**position for position,bit in enumerate(str(num)[::-1])]) |