Skip to content

Instantly share code, notes, and snippets.

@litnimax
litnimax / mqttrpc.py
Created March 6, 2018 11:01
MQTT JSON RPC Client-Server
import asyncio
from asyncio.locks import Event
from asyncio import Queue
import json
import logging
import os
import re
import sys
import uuid
from hbmqtt.client import MQTTClient, ClientException
@litnimax
litnimax / gist:1c5b4c8a351c6b951b138287f164cfeb
Created February 28, 2018 05:21
Gevent MQTT Bottle API server
#-*- coding: utf-8 -*-
# Make sure your gevent version is >= 1.0
import gevent
from gevent import monkey; monkey.patch_all()
from gevent import sleep
from gevent.queue import Queue
from bottle import get, post, request, response, template
from bottle import GeventServer, run
@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 / rds_to_docker.md
Created December 26, 2017 15:57
rds_to_docker.md

Make a backup from RDS

pg_dump -h <rds host> -p 5432 -F c -O -U <rds user> <db name> > db.dump

Restore the backup into a Docker container

docker run --rm --interactive --link <postgres container id>:postgres --volume $PWD/:/tmp/ postgres:latest /bin/bash -c 'pg_restore --verbose --clean --no-acl --no-owner -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres -d <db name> /tmp/db.dump'
@litnimax
litnimax / settings.py
Created July 1, 2017 20:41
Odoo settings ir.config
from openerp import models, fields, api
PARAMS = [
("login", "apps_odoo_com.login"),
("password", "apps_odoo_com.password"),
]
class Settings(models.TransientModel):
@litnimax
litnimax / gist:ac187969fd0100a1730c580e734bba8a
Created June 14, 2017 16:51
asterisk queues postgresql create script
CREATE TABLE asterisk_queue (
name VARCHAR(128) NOT NULL,
musiconhold VARCHAR(128),
announce VARCHAR(128),
context VARCHAR(128),
timeout INTEGER,
ringinuse VARCHAR(3),
setinterfacevar VARCHAR(3),
setqueuevar VARCHAR(3),
setqueueentryvar VARCHAR(3),
@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 / ari_originate.py
Last active October 25, 2021 15:09
Asterisk REST interface origination script to call from console or other apps
#!/usr/bin/env python2.7
# Requirements: pip install ari gevent
import argparse
import ari
import gevent
from gevent.monkey import patch_all; patch_all()
from gevent.event import Event
import logging
from requests.exceptions import HTTPError, ConnectionError
import socket