Skip to content

Instantly share code, notes, and snippets.

@dsuch
dsuch / haproxy.conf
Created June 26, 2013 22:18
HAProxy config for URL-based rate limiting
# At most 10 concurrent connections from a client
acl too_fast fe_sess_rate ge 10
# Matches any path beginning with a given prefix
acl bursts_inclined path_beg -i /client1
# Effectively working as a delay mechanism for clients that are too fast
tcp-request inspect-delay 1000ms
# Fast-path - accept connection if it's not this troublesome client
@dsuch
dsuch / getcust2.py
Created February 3, 2015 19:17
customer.get2
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
# stdlib
from random import choice
# Zato
from zato.server.service import Service
@dsuch
dsuch / getcust1.py
Created February 3, 2015 19:14
customer.get1
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
# stdlib
from json import dumps
from random import choice
# Zato
from zato.server.service import Service
@dsuch
dsuch / put-pymqi.py
Last active July 25, 2019 12:12
MQ Put - PyMQI
import pymqi
queue_manager = 'QM01'
channel = 'SVRCONN.1'
host = '192.168.1.135'
port = '1434'
queue_name = 'TEST.1'
message = 'Hello from Python!'
conn_info = '{}({})'.format(host, port)
@dsuch
dsuch / front_http_plain.conf
Last active January 23, 2019 10:38
Default frontend for HAProxy
frontend front_http_plain
mode http
default_backend bck_http_plain
acl too_fast fe_sess_rate ge 10
acl bursts_inclined path_beg -i /client1
tcp-request inspect-delay 1000ms
tcp-request content accept unless bursts_inclined too_fast
@dsuch
dsuch / sqlserver.txt
Created March 23, 2015 16:39
SQL Server + Zato
I have solved the problem by modifying these lines in zato. I do not know if this has been the best method , but it has worked to give ZATO connectivity with SqlServer.
First of all , I installed and configured FreeTDS and unixODBC (http://blog.tryolabs.com/2012/06/25/connecting-sql-server-database-python-under-ubuntu/)
Then:
In /opt/zato/2.0.0/local/zato-common/src/zato/common/init.py,
add 'mssql+pyodbc': 'SELECT 1',
to var: ping_queries
In /opt/zato/2.0.0/zato-web-admin/src/zato/admin/zato_settings.py,
from sqlalchemy import create_engine
config = {
'username': 'zato1',
'password': 'zato1',
'database': 'zato1',
}
url = 'postgresql+pg8000://{username}:{password}@localhost/{database}'.format(**config)
engine = create_engine(url, echo=True)
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
config = {
'username': 'zato1',
'password': 'zato1',
'database': 'zato1',
}
@dsuch
dsuch / sqlalchemy_json.py
Last active December 9, 2016 19:57
Converting SQLAlchemy objects to JSON
# stdlib
from json import dumps
def to_json(model):
""" Returns a JSON representation of an SQLAlchemy-backed object.
"""
json = {}
json['fields'] = {}
json['pk'] = getattr(model, 'id')
from zato.server.service import Service
class GetFullSecurityDefinitions(Service):
def handle(self):
for value in self.worker_store.request_dispatcher.url_data.basic_auth_config.values():
self.logger.info('\n%s', value.config)