Skip to content

Instantly share code, notes, and snippets.

@osvalr
osvalr / python_sunat_suds_example.py
Created March 25, 2017 04:30
Python SUNAT Example with suds
#!/usr/bin/python
# Originally taken from https://medium.com/@djperalta/python-suds-sunat-example-afc6c37ad426#.mlm9q2lqb
from suds.client import Client
from suds.wsse import *
import requests
import base64
import logging
logging.basicConfig(level=logging.INFO)
@osvalr
osvalr / fsg.sh
Created March 18, 2017 20:45
for-sed-grep script, this is used to replace a string in a set of files without doing sed n-times
#!/bin/bash
# for-grep-sed script used to match a string and replace it in set of files
FGS_FIELD=$1;
FGS_FIELD_REPLACEMENT=$2;
for mf in `grep -rn ${FGS_FIELD} --include=\*.{xml,py} | tr ":" " " | awk '{print $1}' | uniq`; do
sed_replace="sed -i 's/${FGS_FIELD}/${FGS_FIELD_REPLACEMENT}/g' ${mf}";
eval $sed_replace;
done
@osvalr
osvalr / errores_xsl_sunat.md
Last active March 18, 2017 02:26
Errores en Reglas de Validación XSL de la SUNAT

Errores en Reglas de Validación XSL de la SUNAT

  • ValidaExprRegFactura.xsl
  • ValidaExprRegGuiaRemitente.xsl
  • ValidaExprRegNC.xsl
  • ValidaExprRegND.xsl
  • ValidaExprRegPercepcion.xsl
  • ValidaExprRegRetencion.xsl
  • ValidaExprRegSummary.xsl
  • ValidaExprRegVoided.xsl
@osvalr
osvalr / create_x.509_cert.py
Created March 8, 2017 00:17 — forked from ril3y/create_x.509_cert.py
Python script that will generate a x.509 certificate
#!/usr/bin/python
from OpenSSL import crypto, SSL
from socket import gethostname
from pprint import pprint
from time import gmtime, mktime
from os.path import exists, join
CERT_FILE = "myapp.crt"
KEY_FILE = "myapp.key"
@osvalr
osvalr / restore_2_container.sh
Last active September 1, 2017 19:47
Restore a psql dump in a randomed named database inside a container
#!/bin/bash
# Tested in archlinux
function restore_2_container() {
# Container name
container_name=$1
# Random database name
database_name="`shuf -n1 /usr/share/dict/cracklib-small`_`shuf -n1 /usr/share/dict/cracklib-small`"
// taken from a cached page of github.com
.date-selector .date-button {
position: absolute;
top: 0;
width: 18px;
height: 18px;
padding: 4px;
font-size: 12px;
line-height: 12px;
color: #4078c0;
@osvalr
osvalr / array_ordenado.c
Created March 1, 2017 03:42
Read an array and order lower to greater and viceversa
#include <stdio.h>
#include <stdlib.h>
int menor_a_mayor( const void * e1, const void * e2 ){
return ( *(int*)e1 - *(int*)e2 );
}
int mayor_a_menor( const void * e1, const void * e2 ){
return ( *(int*)e2 - *(int*)e1 );
}
#!/bin/bash
# This gist is mainly for export and import your gpg keys in order to backup them individualy,
# use somewhere else or whatever you want to do.
# usage:
# (1) $ export_gpg [email protected] fname
# NOTE: it will create two files: fname-gpg.txt, fname-gpg.key
#
# (2) $ import_gpg fname
@osvalr
osvalr / gpg-import-and-export-instructions.md
Created March 1, 2017 02:35 — forked from chrisroos/gpg-import-and-export-instructions.md
Instructions for exporting/importing (backup/restore) GPG keys

Every so often I have to restore my gpg keys and I'm never sure how best to do it. So, I've spent some time playing around with the various ways to export/import (backup/restore) keys.

Method 1

Backup the public and secret keyrings and trust database

cp ~/.gnupg/pubring.gpg /path/to/backups/
cp ~/.gnupg/secring.gpg /path/to/backups/
cp ~/.gnupg/trustdb.gpg /path/to/backups/

or, instead of backing up trustdb...

@osvalr
osvalr / x509_sign.py
Created February 25, 2017 19:36
Sign XML file in python with a x509 certificate
# coding: utf-8
from lxml import etree
from signxml import xmldsig
cert = open('cert.pem').read()
key = open('key.pem').read()
doc = etree.parse('sample.xml').getroot()