Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Gonçalves danielgoncalves

  • Base4 Sistemas
  • Catanduva/SP
  • Twitter @spanazzi
View GitHub Profile
@danielgoncalves
danielgoncalves / lazy_qs_demo.py
Last active Oct 9, 2020 — forked from jsbueno/lazyquicksort.py
Lazy sorter - an iterator that yields items in sorted order, lazily
View lazy_qs_demo.py
import random
import string
from lazyquicksort import lazy_sort
def chars(length):
options = string.ascii_lowercase
return ''.join([random.choice(options) for i in range(length)])
@danielgoncalves
danielgoncalves / git-apply-patch.md
Created Feb 21, 2020 — forked from emmanueltissera/git-apply-patch.md
Generate a git patch for a specific commit
View git-apply-patch.md

Creating the patch

git format-patch -1 <sha>
OR
git format-patch -1 HEAD

Applying the patch

git apply --stat file.patch # show stats.
git apply --check file.patch # check for error before applying

@danielgoncalves
danielgoncalves / postgres-cheatsheet.md
Created Jan 22, 2020 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet
View postgres-cheatsheet.md

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
View singleton_way_to_go.dart
// (!) This implementation seems to work;
// Trying this in DartPad results in "s = false" and "f = true" as expected.
// This was taken from https://gist.github.com/theburningmonk/6401183
class FooBar {
static final FooBar _instance = new FooBar._internal();
factory FooBar() => _instance;
FooBar._internal() {
// initialization logic here
@danielgoncalves
danielgoncalves / reportlab_barcode.py
Created Apr 23, 2018 — forked from luxinyan/reportlab_barcode.py
Generate barcode with reportlab.
View reportlab_barcode.py
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
from reportlab.lib.units import mm
#I"ll be generating code39 barcodes, others are available
from reportlab.graphics.barcode import code39
# generate a canvas (A4 in this case, size doesn"t really matter)
c=canvas.Canvas("barcode_example.pdf",pagesize=A4)
# create a barcode object
# (is not displayed yet)
@danielgoncalves
danielgoncalves / ipc.py
Last active Nov 23, 2017 — forked from dankrause/ipc.py
Simple socket IPC in python
View ipc.py
# Copyright 2017 Dan Krause
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@danielgoncalves
danielgoncalves / knownpaths.py
Created Jan 11, 2017 — forked from mkropat/knownpaths.py
Python wrapper around the SHGetKnownFolderPath Windows Shell function
View knownpaths.py
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 Jul 8, 2020
PyESCPOS sandbox script
View sandbox.py
# -*- 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 Aug 29, 2015
XML de referência usado na função TesteFimAFim
View TesteFimAFim.xml
<?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 Mar 28, 2015
Boneco do Extrato do CF-e (Cupom Fiscal eletrônico) para o SAT-CF-e
View extrato-sat.py
# 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()