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 / tcp_bridge.py
Last active August 13, 2023 19:39
Simple TCP bridge in python
"""
requirements:
$ pip install click
run with:
$ python tcp_proxy --listen=:5000 --connect=192.168.1.100:5000
"""
import socket
@tiagocoutinho
tiagocoutinho / nmap.md
Last active May 16, 2020 07:39
nmap examples
# find hosts with port 80 open
nmap -PE -p 80 xxx.yyy.zzz.*
@tiagocoutinho
tiagocoutinho / virtual_local_net_create.sh
Last active May 13, 2020 19:24
virtual local network
# Execute with sudo
# Recipe at: https://unix.stackexchange.com/questions/152331/how-can-i-create-a-virtual-ethernet-interface-on-a-machine-without-a-physical-ad
NAME=bl04-eth
ALIAS=$NAME:0
MAC=00:22:22:ff:ff:ff
IP=192.168.100.199
# Create interface
ip link add $NAME type dummy
@tiagocoutinho
tiagocoutinho / README.md
Last active December 19, 2023 07:57
Virtual serial line (RS232) on linux with socat and pyserial

Virtual serial line

Virtual serial line on linux with socat, python server & client

Run on terminal 1:

socat -d -d pty,raw,echo=0,link=/tmp/cryocon_simulator pty,raw,echo=0,link=/tmp/cryocon

Run on terminal 2:

"""
Example output:
2020-05-05 20:04:47,200 trying to connect to bl04cryocon:5000
2020-05-05 20:04:47,701 error: TimeoutError()
2020-05-05 20:04:47,702 trying to connect to bl04cryocon:5000
2020-05-05 20:04:48,203 error: TimeoutError()
2020-05-05 20:04:48,204 trying to connect to bl04cryocon:5000
2020-05-05 20:04:48,706 error: TimeoutError()
2020-05-05 20:04:48,707 trying to connect to bl04cryocon:5000
@tiagocoutinho
tiagocoutinho / PowerSupply.py
Last active April 2, 2020 15:59
Tango Server restart "dynamic" attributes
import os
import sys
import time
import threading
from tango.server import Device, attribute, command
attrs = [
dict(name='voltage', dtype=float, label='Voltage', fget=lambda dev: 1.2345),
dict(name='power_level', dtype=str, label='Power level', fget=lambda d: 'high')
@tiagocoutinho
tiagocoutinho / asyncio_serial_stream.py
Last active July 26, 2021 04:56
gevent & asyncio serial line on posix systems
import asyncio
import serial_asyncio
I=0
async def loop():
global I
while True:
await asyncio.sleep(0.1)
I += 1
@tiagocoutinho
tiagocoutinho / ginotify_simple.py
Created October 2, 2019 06:13
gevent friendly intofy_simple
"""
A gevent friendly version of inotify_simple
Either instanciate INotify objects directly from `ginotify_simple.INotify`:
```python
from ginotify_simple import INotify, flags
ify1 = INotify()
@tiagocoutinho
tiagocoutinho / ginotify.py
Last active October 2, 2019 05:37
gevent friendly inotify
"""
A gevent friendly version of inotify
Either instanciate Inotify (or InotifyTree) objects directly from `ginotify.Inotify`:
```python
from ginotify import Inotify
ify1 = Inotify()
@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)]