Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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
@jsenin
jsenin / howto_snmp_hex_values_to_date_time.txt
Created June 9, 2020 10:21
understand snmp hex values to extract date time values
extract values using snmp-walk
# filter by dates 07E4 -> 2020 year
snmpwalk -v2c -c community gpon.my.net 1.3.6.1.4.1.2011.6.128.1.1.2 | grep "07 E4"
# mibs from https://code.getnoc.com/noc/noc/-/blob/master/cmibs/huawei_xpon_mib.py
"HUAWEI-XPON-MIB::hwGponDeviceOltLastUpTime": "1.3.6.1.4.1.2011.6.128.1.1.2.21.1.17",
SNMPv2-SMI::enterprises.2011.6.128.1.1.2.21.1.17.4194304000 = Hex-STRING: 07 E4 06 09 0A 2E 07 00 2B 02 00
SNMPv2-SMI::enterprises.2011.6.128.1.1.2.21.1.17.4194304768 = Hex-STRING: 07 E4 02 13 0A 0E 00 00 2B 01 00
"HUAWEI-XPON-MIB::hwGponDeviceOltLastDownTime": "1.3.6.1.4.1.2011.6.128.1.1.2.21.1.18",
SNMPv2-SMI::enterprises.2011.6.128.1.1.2.21.1.18.4194304000 = Hex-STRING: 07 E4 06 09 0A 2D 38 00 2B 02 00
@jsenin
jsenin / find_mips_global_pointer_ida.py
Created May 30, 2020 16:59
Trying to find global pointers by hand at MIPS code
# Script for IDA
# find for MIPS global pointer and try to create a function
#
# conversion hex to opcode at https://www.eg.bucknell.edu/~csci320/mips_web/
# 0x3c1c8064
# LUI $gp 0x8064
#
# 0x279c1c70
# ADDIU $gp $gp 0x1C70
@jsenin
jsenin / update_changelog.sh
Created May 19, 2020 08:29
Update CHANGELOG adding all previous commits subject by default
#!/bin/bash
current_tag=production_$(date +'%Y%m%d')
git tag $current_tag
previous_tag=$(git tag -l 'prod*' --sort=-committerdate | grep -v $current_tag | head -n1)
commit_description=$(git log $previous_tag..$current_tag --pretty=format:" * %s")
if ! [ -f CHANGELOG.md ]; then touch CHANGELOG.md; fi;