Skip to content

Instantly share code, notes, and snippets.

@jsenin
jsenin / soap_envelope.py
Created May 18, 2017 11:40
soap xml with namespaces using lxml and python
from lxml import etree
from lxml.builder import ElementMaker
class NewRpcMessageEncoder(object):
def _envelope(self, request_id, hold_requests):
SOAP_ENV = "http://schemas.xmlsoap.org/soap/envelope/"
SOAP_ENC = "http://schemas.xmlsoap.org/soap/encoding/"
XSD = "http://www.w3.org/2001/XMLSchema"
XSI = "http://www.w3.org/2001/XMLSchema-instance"
@jsenin
jsenin / helpers.php
Created August 5, 2016 08:36
improve dd laravel function
/**
* /vendor/laravel/framework/src/Illuminate/Support/helpers.php
*/
if (! function_exists('dd')) {
/**
* Dump the passed variables and end the script.
*
* @param mixed
* @return void
@jsenin
jsenin / comtrend-ar5315u-oem-firmware.txt
Created September 23, 2016 23:50
comtrend-ar5315u-oem-firmware, alternative boot configured at CFE Boot image (0=latest, 1=previous) => 1
Resetting board in 0 seconds...HELO
CPUI
L1CI
DRAM
----
PHYS
PHYE
DDR1
333H
SIZ3
@jsenin
jsenin / changelog.py
Created May 5, 2022 09:49
script for finding versio releases in java code, build a changelog and launch tags to git
import re
from pydriller import Repository
def extract_version(content):
regex = r"<artifactId>myapp<\/artifactId>.*\n^\-.*<version>(.*)<\/version>.*\n^\+.*<version>(.*)<\/version>"
matches = re.findall(regex, content, re.MULTILINE)
if matches:
return matches[0][0], matches[0][1]
@jsenin
jsenin / normalize_filenames.py
Created March 22, 2022 22:39
drop characters non visibles at filenames. Usually because mixed charset codifications
import glob
import shutil
files = glob.glob("/home/jorge/Music/**", recursive=True)
for current in files:
try:
new = current.encode('utf8', 'ignore')
shutil.move(current, new)
except Exception as exc:
print(str(exc))
@jsenin
jsenin / AsteriskUtil.py
Created March 1, 2022 13:01
py-asterisk error from ExceptionBase need to provide a message
# Asterisk/Util.py
class EventCollection(Logging.InstanceLogger):
'''
Utility class to allow grouping and automatic registration of event.
'''
def __init__(self, initial=None):
'''
If <initial> is not None, register functions from the list <initial>
waiting for events with the same name as the function.
@jsenin
jsenin / exception_subclass.py
Created December 2, 2021 06:49
A proposal about exception subclassing
#---- current behaviour
# class UsernameTooShortError(Exception):
# MSG = 'Username too short'
# pass
# def add_user(username=None):
# if len(username) < 4:
# raise UsernameTooShortError()
@jsenin
jsenin / snmp_date_pack_and_unpack_example.py
Last active June 21, 2021 12:02
pack and unpack octects from snmp oids in python
import struct
import datetime
ts = 1620386580.0
dt = datetime.datetime.fromtimestamp(ts)
packed = struct.pack(">hbbbbbb", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond)
print ("packed", packed, ts )
tp = dt.timetuple() # expand values in a tuple
import time
@jsenin
jsenin / python.spec.snippet
Created May 25, 2021 11:16
ultisnip snip for mamba specs
# reduce the time whe your write a mamba spec file
# easy use: :UltiSnipsEdit
#
global !p
def sanitize_spec_fn(fn):
return fn.replace("spec.py", "").replace("_", " ")
endglobal
snippet mamba "mamba spec skel"
from mamba import description, context, it
@jsenin
jsenin / in_memory_repository.py
Last active June 23, 2020 09:26
A python in memory repository implementation
import pickle
class BaseRepository:
def put(self, entity):
raise NotImplementedError
def find_by_id(self, entity_id):
raise NotImplementedError