Skip to content

Instantly share code, notes, and snippets.

View justinmassiot's full-sized avatar

Justin MASSIOT justinmassiot

View GitHub Profile
@justinmassiot
justinmassiot / regex_replace.py
Last active December 25, 2023 20:06
Replacements based on advanced regular expressions.\ We also use a temporary file thanks to the 'tempfile' library.
r'''
The script uses regular expressions (regex) to perform replacements on a file.
The regex replacement is applied once by line.
The search pattern is built like this:
(designator)-(pin name)space((prefixes, optional)(component names))
Example:
([A-Z]+[0-9]+)-([^ ]+) ((NC_|DNP_)?(2000UF|SS2040FL|DMP1046UFDB|TMP1075DSGR))
^ ^ ^^ ^ match group 5
^ ^ ^^ match group 4
^ ^ ^ match group 3
@justinmassiot
justinmassiot / argparse.py
Last active December 25, 2023 19:31
**Advanced usage of command line switches (a.k.a. arguments) thanks to the 'argparse' library.** The help message of this script should look like this: ``` usage: argparse.py [-h] [-r RECIPES] [-p] [-q] [-l LOGFILE] client A beautiful description.
import argparse
# command line options
# the help message shows the default values
argParser = argparse.ArgumentParser( \
formatter_class=argparse.ArgumentDefaultsHelpFormatter, \
description='''A beautiful description.''' \
)
argParser.add_argument('client', help='Reference code of the target client. Must exist in the mapping dictionary.') # mandatory
argParser.add_argument('-r', '--recipes', help='JSON file containing the recipes for pins renaming. Must contain one section by client.', default='CLIENTS_Remap_Part-PinNames.json')

Subversion data format and revisions

Introduction

Each repository follows a repository format and a data store format.

Repository format (schema)

SUBVERSION VERSION NUMBER SCHEMA VERSION
@justinmassiot
justinmassiot / load_database_dump.py
Last active February 8, 2025 13:27
Database management example with OdooRPC: https://pythonhosted.org/OdooRPC/ref_db.html#odoorpc.db.DB Dump an Odoo Online database: https://{{db_name}}.odoo.com/saas_worker/dump Dump any database: https://pythonhosted.org/OdooRPC/ref_db.html#odoorpc
# https://pythonhosted.org/OdooRPC/ref_db.html#odoorpc.db.DB
import sys # in order to capture stdin
import os
import argparse
import odoorpc # pip install odoorpc
from datetime import datetime
argParser = argparse.ArgumentParser()
# Pre-requisite: `pip install dnspython`
# Source: https://github.com/scottbrady91/Python-Email-Verification-Script
import re
import smtplib
import dns.resolver
# Address used for SMTP MAIL FROM command
fromAddress = '[email protected]'
@justinmassiot
justinmassiot / get_ipaddress.py
Last active December 13, 2023 17:14
Obtain the IP address of the designated interface (Linux systems)
import socket
def get_ipaddress(network='wlan0'):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', network[:15])
)[20:24])
target_list_id = 6 # "[FR] Newsletter"
for rec in records: # contacts on which to work (user selection)
existing_contacts = env['mailing.contact'].search([('email', '=', rec.email)])
if len(existing_contacts) > 1:
raise UserError(rec.name + " has multiple entries in the mailing contacts.\nPlease clean things up and get back here after having removed the duplicates.")
elif len(existing_contacts) == 1:
for recipient in existing_contacts: # should get exactly 1 recipient
list_ids = [listid.id for listid in recipient.list_ids] # get all the lists the user is subscribed to
if target_list_id in list_ids:
@justinmassiot
justinmassiot / split_git_subdir.sh
Last active December 11, 2023 15:28
Instructions to export a subdirectory to a new git repository and keep the history
# Source: https://ao.gl/how-to-split-a-subdirectory-to-a-new-git-repository-and-keep-the-history/
git filter-branch --prune-empty --subdirectory-filter relative/path/to/subdirectory your_current_branch_name
git remote set-url origin https://github.com/subfolder/your_new_sub_repo.git
git push -u origin your_current_branch_name
@justinmassiot
justinmassiot / SwapEscapeSculptKeyboard.ahk
Last active December 12, 2023 08:12
**Important warning**: the file encoding must be UTF-8-BOM (or ANSI)! Otherwise AutoHotKey will complain for a non-recognized character.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
Esc::²
²::Esc