Skip to content

Instantly share code, notes, and snippets.

View guewen's full-sized avatar

Guewen Baconnier guewen

View GitHub Profile
@guewen
guewen / benchmark_odoo_recordset_union.py
Last active May 4, 2022 08:38
benchmark odoo recordset union
# to run in odoo shell
import timeit
code_recordset = """
result = env['product.product'].browse()
for record in records:
result |= record
"""
@guewen
guewen / load_file.py
Last active January 16, 2023 12:19
odoo: load data file from shell
from odoo.tools import convert_file
convert_file(env.cr, 'account_invoice_sent', 'wizards/account_invoice_state_view.xml', {}, mode='update', kind='data')
env.cr.commit()
def reload(addon, path):
from odoo.tools import convert_file
convert_file(env.cr, addon, path, {}, mode='update', kind='data')
env.cr.commit()
@guewen
guewen / normalize_query_function.sql
Last active October 16, 2019 09:07
pg_stat_statements normalization
CREATE OR REPLACE FUNCTION normalize_query(IN TEXT, OUT TEXT) AS $body$
SELECT
regexp_replace(
lower($1),
-- Remove IN values
'in\s*\([,\s\?]*\)', 'in (...)', 'g' )
;
$body$
LANGUAGE SQL;
@guewen
guewen / ir_http.py
Created January 19, 2017 15:53
Log Odoo cache statistics
# -*- coding: utf-8 -*-
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
import logging
import random
import threading
from collections import defaultdict
@guewen
guewen / keybase.md
Created October 12, 2016 11:08
keybase proof

Keybase proof

I hereby claim:

  • I am guewen on github.
  • I am guewen (https://keybase.io/guewen) on keybase.
  • I have a public key ASAQTfK_7H26dnaTrYfE2YF_iXZotEEMvW97PWhFgilG2Ao

To claim this, I am signing this object:

@guewen
guewen / Dockerfile
Created July 15, 2015 09:28
Odoo Runbot Dockerfile
# Dockerfile
FROM ubuntu:14.04
# Set the locale
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
# Install dependencies
@guewen
guewen / s3sync.py
Last active August 29, 2015 14:24
Sync logs from S3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Dowload new log files from S3.
New files are compressed with gzip and only new files are downloaded.
"""
from __future__ import print_function
@guewen
guewen / cache.sql
Last active May 18, 2018 12:37
PostgreSQL maintenance queries
-- Needs pg_buffercache
select count(*) from pg_buffercache;
@guewen
guewen / ideas.markdown
Created May 27, 2015 08:26
Connector improvement ideas

Ideas

  • Graph view for jobs statistics (durations, throughputs, grouped by channels, ...)
  • Attribute in Retryable errors defining if the Retry should increment the retry count or not (allowing to do infinite retries on some types of errors like when we wait for a magento payment, when other retryable errors such as network errors still increase the retry count)
  • Define shortcuts for the imports as an API (from openerp.addons.connector import job, install_in_connector, ...)
  • See if we can remove install_in_connector() by checking in ir.module.module with caching of the result
  • Retryable errors with a Retry pattern (see OCA/connector-magento#26)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
from urllib2 import urlopen
import bs4 as BeautifulSoup
html = urlopen('http://menus.epfl.ch/cgi-bin/getMenus?resto_id=42&pagejahia=1')
soup = BeautifulSoup.BeautifulSoup(html)