Skip to content

Instantly share code, notes, and snippets.

View danielgoncalves's full-sized avatar

Daniel Gonçalves danielgoncalves

View GitHub Profile
@danielgoncalves
danielgoncalves / knownpaths.py
Created January 11, 2017 17:20 — forked from mkropat/knownpaths.py
Python wrapper around the SHGetKnownFolderPath Windows Shell function
import ctypes, sys
from ctypes import windll, wintypes
from uuid import UUID
class GUID(ctypes.Structure): # [1]
_fields_ = [
("Data1", wintypes.DWORD),
("Data2", wintypes.WORD),
("Data3", wintypes.WORD),
("Data4", wintypes.BYTE * 8)
@danielgoncalves
danielgoncalves / sandbox.py
Last active July 8, 2020 03:21
PyESCPOS sandbox script
# -*- coding: utf-8 -*-
# Requires https://github.com/base4sistemas/pyescpos
# Have a look at https://github.com/base4sistemas/pyescpos/wiki
from __future__ import unicode_literals
from __future__ import print_function
import logging.config
from escpos import showcase
from escpos.conn.usb import USBConnection
@danielgoncalves
danielgoncalves / TesteFimAFim.xml
Last active August 29, 2015 14:24
XML de referência usado na função TesteFimAFim
<?xml version="1.0"?>
<CFe>
<infCFe versaoDadosEnt="0.06">
<ide>
<CNPJ>08427847000169</CNPJ>
<signAC>SGR-SAT SISTEMA DE GESTAO E RETAGUARDA DO SAT</signAC>
<numeroCaixa>002</numeroCaixa>
</ide>
<emit>
<CNPJ>61099008000141</CNPJ>
@danielgoncalves
danielgoncalves / extrato-sat.py
Created March 28, 2015 21:41
Boneco do Extrato do CF-e (Cupom Fiscal eletrônico) para o SAT-CF-e
# Depende de PyESCPOS (https://github.com/base4sistemas/pyescpos)
# Testado em uma Daruma DR700 L-e v01.21.00
# Resultado: https://plus.google.com/105886422423352640759/posts/YBedvhKL8SQ?pid=6131402497594282098&oid=105886422423352640759
from escpos.serial import SerialSettings
from escpos.impl.daruma import DarumaGeneric
conn = SerialSettings.as_from('COM1:9600,8,1,N').get_connection()
printer = DarumaGeneric(conn)
printer.init()
@danielgoncalves
danielgoncalves / buscarcep.py
Last active August 29, 2015 14:02
Exemplo de uso do webservice "Buscar CEP" (Python 2.7)
# -*- coding: utf-8 -*-
#
# buscarcep.py
#
# Exemplo de uso do webservice http://buscarcep.com.br/
# Para Python 2.7
#
# Daniel Gonçalves <daniel@base4.com.br>
#
@danielgoncalves
danielgoncalves / logr.py
Last active December 13, 2015 17:19
Minimalist tool to search and list occurrences of unique exceptions in log files. The exceptions should be logged using the `exception` method.
# -*- coding: utf-8 -*-
#
# logr.py is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# logr.py is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@danielgoncalves
danielgoncalves / example.py
Created September 5, 2011 21:46
Validate an IPv4 address.
def is_ip(value):
"""IP simple validation in response to blog post http://goo.gl/L9cKh"""
try:
bytes = [int(e) for e in value.split('.') if 0 <= int(e) <= 255)]
except ValueError:
return False
return len(bytes) == 4