Skip to content

Instantly share code, notes, and snippets.

@litnimax
litnimax / main.py
Created July 11, 2020 07:51 — forked from mlaitinen/main.py
Odoo 12 Prometheus instrumentation
##############################################################################
#
# Author: Miku Laitinen / Avoin.Systems
# Copyright 2019 Avoin.Systems
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
[options]
#
# WARNING:
# If you use the Odoo Database utility to change the master password be aware
# that the formatting of this file WILL be LOST! A copy of this file named
# /etc/odoo/openerp-server.conf.template has been made in case this happens
# Note that the copy does not have any first boot changes
#-----------------------------------------------------------------------------
# Odoo Server Config File - TurnKey Linux
@litnimax
litnimax / add-minion.sh
Created January 11, 2020 12:13 — forked from Silvenga/add-minion.sh
Remotely Authorize and Provision a Salt Minion
#!/bin/bash
# apt-get install sshpass
# http://docs.saltstack.com/en/latest/topics/tutorials/preseed_key.html
BOOTSTRAP=/srv/minion-bootstrap.sh
LOG_LOCATION=/tmp/minion-bootstrap.log
TMP=/tmp/salt
if [[ -z "$1" ]] || [[ -z "$2" ]] ; then
@litnimax
litnimax / psqlfix.txt
Last active November 7, 2019 04:27
Change postgres default template0 to UTF8 encoding
update pg_database set datallowconn = TRUE where datname = 'template0';
\c template0
update pg_database set datistemplate = FALSE where datname = 'template1';
drop database template1;
create database template1 with template = template0 encoding = 'UTF8';
update pg_database set datistemplate = TRUE where datname = 'template1';
template1
update pg_database set datallowconn = FALSE where datname = 'template0';
@litnimax
litnimax / periodic.py
Created February 10, 2018 14:49 — forked from akaIDIOT/periodic.py
Call something periodically using asyncio
import asyncio
def call_periodic(interval, callback, *args, **kwargs):
# get loop as a kwarg or take the default one
loop = kwargs.get('loop') or asyncio.get_event_loop()
# record the loop's time when call_periodic was called
start = loop.time()
def run(handle):
@litnimax
litnimax / ble.py
Created February 26, 2017 08:22 — forked from tito/ble.py
Bluetooth Low Energy explorer, working on MacOSX 10.9 using latest Pyobjus.
from pyobjus import autoclass, protocol
from pyobjus.dylib_manager import load_framework, INCLUDE
(CBCentralManagerStateUnknown,
CBCentralManagerStateResetting,
CBCentralManagerStateUnsupported,
CBCentralManagerStateUnauthorized,
CBCentralManagerStatePoweredOff,
CBCentralManagerStatePoweredOn) = range(6)
@litnimax
litnimax / odoo-sh.py
Created October 18, 2016 16:24 — forked from dreispt/odoo-sh.py
Odoo Shell: run Odoo commands without a server RPC connection
"""
Setup:
Assuming Odoo 8.0 sources at ~/odoo:
$ cp odoo-sh.py ~/odoo
$ cd ~/odoo
$ python -i odoo-sh.py
Usage example:
>>> env = connect('my-db-name')
>>> Users = env['res.users']
@litnimax
litnimax / install-odoo.sh
Created September 5, 2016 07:08 — forked from yelizariev/install-odoo.sh
install odoo from source. Script is maintained on github now: https://github.com/yelizariev/install-odoo
if [ "$(basename $0)" = "install-odoo.sh" ]; then
echo "don't run install-odoo.sh, because it's not fully automated script. Copy, paste and execute commands from this file manually"
exit 0
fi
#### Detect type of system manager
export SYSTEM=''
pidof systemd && export SYSTEM='systemd'
@litnimax
litnimax / gist:012569768c0e2210021b651e5ccd0e09
Created July 28, 2016 08:51 — forked from tmc/gist:777085
multiprocessing gevent chat example
import sys
import gevent
from gevent.monkey import patch_all; patch_all()
from gevent import server, event, socket
from multiprocessing import Process, current_process, cpu_count
"""
Simple multiprocess StreamServer that proxies messages between clients.
Avoids using a multiprocessing.Event since it blocks on a semaphore.
@litnimax
litnimax / zmq_socket.py
Created March 8, 2016 10:11 — forked from anonymous/gist:bc82a0bea35a5cb3ce01
ZMQ Socket with timeout
from functools import update_wrapper
import zmq
class Socket(zmq.Socket):
def __init__(self, ctx, type, default_timeout=None):
zmq.Socket.__init__(self, ctx, type)
self.default_timeout = default_timeout
def on_timeout(self):