Skip to content

Instantly share code, notes, and snippets.

View tiagocoutinho's full-sized avatar

Jose Tiago Macara Coutinho tiagocoutinho

View GitHub Profile
@tiagocoutinho
tiagocoutinho / GeventDS.py
Created September 14, 2015 05:55
Gevent enabled TANGO device server
"""
Demonstrate usage of TANGO DS with gevent.
Usage example: Go to jive and in the menu select Edit->Create server, then
fill in the fields:
Server (ServerName/Instance): GeventDS/test1
Class: Gevent
Devices: test/gevent/1
click Register server.
@tiagocoutinho
tiagocoutinho / CT2.py
Last active October 14, 2015 08:36
POGO PythonHL code
# -*- coding: utf-8 -*-
#
# This file is part of the CT2 project
#
# Copyright 2015 European Synchrotron Radiation Facility, Grenoble, France
#
# Distributed under the terms of the LGPL license.
# See LICENSE.txt for more info.
""" CT2 (P201/C208) ESRF counter card
@tiagocoutinho
tiagocoutinho / proxy.py
Created April 23, 2016 13:06
Python object proxy
'''
An implementation object proxy pattern in python
Example::
from proxy import Proxy
class A(object):
def __init__(self, base):
self.base = base
def plus(self, *a):
@tiagocoutinho
tiagocoutinho / motion.py
Created April 2, 2017 20:24
python progress bar (tqdm) axes motion
# -*- coding: utf-8 -*-
import time
import collections
class Motor(object):
Motion = collections.namedtuple('Motion', 'ipos fpos start_time end_time')
@tiagocoutinho
tiagocoutinho / ps-simulator
Created October 5, 2017 16:43
power supply tcp simulator
#!/usr/bin/env python3
import time
import random
import logging
import gevent.server
DEFAULT_BIND = ''
DEFAULT_PORT = 45000
@tiagocoutinho
tiagocoutinho / hexdumps.py
Created November 12, 2017 21:06
hexdump with multiple memory zones
import hexdump
def binaries_gen(binaries):
"""
Generates a sequence of bytes from a seq<(offset, bytes)>
If there are gaps between the bytes the generator yields N None where N is
the length of the gap
Example::
@tiagocoutinho
tiagocoutinho / s2net.py
Last active November 9, 2023 00:40
Python serial to tcp
"""
tsb.py -- A telnet <-> serial port bridge
Copyright (C) 2005 Eli Fulkerson
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
@tiagocoutinho
tiagocoutinho / zero.py
Last active May 1, 2020 17:20
Python thread pitfall
# I dare you to find an execution that prints out 0
# (at least using the CPython implementation)
from threading import Thread
C, N = 0, 1_000_000
def f(inc=1):
global C, N
for i in range(N):
C += inc
@tiagocoutinho
tiagocoutinho / xmlrpclib_gevent.py
Last active January 28, 2018 08:51
Safe XML RPC calls in multiple gevent tasks
"""
Safe XML RPC calls in multiple gevent tasks. Basically, it serializes calls.
Assuming you are running a server like this::
import time
from SimpleXMLRPCServer import SimpleXMLRPCServer
def is_even(n):
time.sleep(3)
@tiagocoutinho
tiagocoutinho / dining_phylosophers_threading.py
Last active June 28, 2019 19:56
Dinning phylosophers threading python
import time
import random
import threading
def sleep():
time.sleep(random.random())
N = 5
sticks = [threading.Lock() for n in range(N)]