Skip to content

Instantly share code, notes, and snippets.

View amatmv's full-sized avatar
💭
🙏

Amat Martínez amatmv

💭
🙏
View GitHub Profile
@amatmv
amatmv / get_django_session_value.py
Last active December 23, 2021 09:12
Get values from redis sessions in Django
from django.conf import settings
from importlib import import_module
from redis import Redis
import base64
import json
SESSION_KEY = 'examplehashsessionid'
def get_value_from_redis(key=SESSION_KEY):
""" Get value from the DB using redis cli """
@amatmv
amatmv / show_urls.py
Last active March 17, 2021 15:55
View django urls
import re
import json
from django.urls import URLPattern, URLResolver, reverse
from django.utils import translation
from django.core.exceptions import ViewDoesNotExist
from django.core.management import color
from django.contrib.admindocs.views import simplify_regex
from kavehome_pt import settings
@amatmv
amatmv / git-squash.sh
Last active November 10, 2020 08:12 — forked from gdalmau/git-squash.sh
git-squash: script to create a squashed patch from a branch.
#! /bin/sh
# Produce a squash-commit patch from a branch of changes
# Usage example: sh git-squash.sh master <branch_to_squash>
MASTER=$1
PATCHBRANCH=$2
SQUASHBRANCH="$PATCHBRANCH-squash"
git checkout -b "$SQUASHBRANCH" $MASTER &&
git merge --squash "$PATCHBRANCH" &&
git commit -a -m "Squash commit" &&
@amatmv
amatmv / generate_diff_prs.sh
Last active July 14, 2020 15:17
Generate a big diff from list of Pull Requests
#!/bin/bash
#
# Usage:
#
# Indicate the name of the output file with the flag: -f
# Indicate the list of Pull Requests with the flat: -p. The format is a quoted string sepparated by spaces.
#
while getopts p:f: option
do
@amatmv
amatmv / uninstall_modules.py
Last active October 8, 2019 08:38
Print the queries that may be executed to uninstall the module. The module to uninstall will be indicated with a SQL Regex with the parameter --module.
# coding=utf-8
from erppeek import Client
import click
def uninstall_module_get_queries(client, module_id):
queries = []
imd_o = client.model('ir.model.data')
module_o = client.model('ir.module.module')
@amatmv
amatmv / vim_cheatsheet.md
Last active April 4, 2018 09:35
Vim cheatsheet

Vim Cheatsheet

Disclaimer: This cheatsheet is summarized from personal experience and other online tutorials. It should not be considered as an official advice.

Global

:help keyword # open help for keyword
:o file       # open file
@amatmv
amatmv / parse_comer_cnmc.py
Last active October 9, 2017 12:15
Update XML with REE comers info with the info of the CNMC
# -*- coding: utf-8 -*-
import click
import csv
import re
import os
import subprocess
from xml.etree.ElementTree import Element, SubElement
from xml.etree import ElementTree as ET
from xml.dom import minidom
import sys
@amatmv
amatmv / smtp_server_python.py
Created September 27, 2017 10:56
SMTP Testing Server
from datetime import datetime
import asyncore
from smtpd import SMTPServer
class EmlServer(SMTPServer):
no = 0
def process_message(self, peer, mailfrom, rcpttos, data):
filename = '%s-%d.eml' % (datetime.now().strftime('%Y%m%d%H%M%S'),
self.no)
f = open(filename, 'w')
@amatmv
amatmv / merge_trans.sh
Last active September 18, 2017 09:44
MergeTool For translations
#!/bin/bash
# This script should be placed in the /tools folder of the ERP base directory.
# And be executed from the /erp directory this way: ./tools/merge_trans.sh -m <module_name>
module=$2
if [[ -z $1 ]] || [[ "$1" != "-m" ]] || [[ "$1" = "-h" ]] || [[ "$1" = "--help" ]] || [[ -z $2 ]]; then
echo "Indicate the module that has conflicts this way: -m <module-name>."
else
line=1
module_dir=`cd .. | locate -r /$module$ | grep "erp/addons" | sed -n "$line"p`