Skip to content

Instantly share code, notes, and snippets.

View enric1994's full-sized avatar

Enric Moreu enric1994

View GitHub Profile
@enric1994
enric1994 / iou.py
Last active November 9, 2018 17:10
Intersection of Union (IoU). Evaluates the accuracy using the ground truth and the prediction
def eval_iou(img1,img2):
m_img1 = img1 > 0
img1[m_img1] = 1
m_img2 = img2 > 0
img2[m_img2] = 1
overlap = img1*img2
union = img1 + img2
@enric1994
enric1994 / one_line_print.py
Created November 9, 2018 14:51
Print stuff in Python 2.7 always in the same line using carriage return
import sys,time
for i in xrange(100):
time.sleep(1)
sys.stdout.write('\r One line print! ' + str(i))
sys.stdout.flush()
@enric1994
enric1994 / telegram.py
Last active September 10, 2019 11:22
Simple Telegram bot for Python 2.7
#!/usr/bin/python2
#pip install telebot
import telebot
# Step 1. Create a bot and get the API key using the BotFather: https://telegram.me/BotFather
telegramToken='INSERT_API_KEY_HERE'
# Step 2. Start a conversation with your new bot using the /start command
@enric1994
enric1994 / alive.yml
Created November 16, 2018 14:51
Keep a Docker container alive without running any task
version: "3"
services:
python:
image: python
command: "tail -f /dev/null"
@enric1994
enric1994 / db.py
Created November 18, 2018 18:20
MySQL Python3 connector
#!/usr/bin/python3
#pip install mysql-connector-python
import mysql.connector
cnx = mysql.connector.connect(user='user',password='password',host='hostname', database='dbname')
cursor = cnx.cursor()
cursor.execute('SELECT * FROM users')
response= cursor.fetchall()
cnx.commit()
@enric1994
enric1994 / unittest.py
Last active November 18, 2018 19:51
Python Unit Testing
'''Place all the tests in a 'tests' folder,
start the name of each file with 'test' (e.g. test_string.py).
Finally run: $ python -m unittest discover <tests_folder_location>
'''
import unittest
class TestStringMethods(unittest.TestCase):
def test_upper(self):
@enric1994
enric1994 / secure_proxy.yml
Created November 21, 2018 14:15
Docker Compose file to setup a HTTPS proxy that exposes a web server.
version: '3'
services:
nginx-proxy:
image: jwilder/nginx-proxy
ports:
# Check that the other applications are not using the ports 80 or 443
- "80:80"
# By default this proxy redirects from the port 80 to the 443
- "443:443"
@enric1994
enric1994 / install_docker.md
Last active November 9, 2020 07:57
Install Docker and Docker-Compose in 10 seconds
  1. Install docker: curl -sSL https://get.docker.com/ | sh
  2. Install docker compose:
  • Check the latest release at https://github.com/docker/compose/releases
  • Using latest version : sudo curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  • sudo chmod +x /usr/local/bin/docker-compose
  1. Setup docker to work without sudo: sudo usermod -aG docker $USER
  2. Log out from the computer.
  3. Log in and check version: docker -v; docker-compose -v
@enric1994
enric1994 / Dockerfile.webcam
Last active May 23, 2024 22:37
Using the webcam in a GPU enabled Docker Compose
FROM tensorflow/tensorflow:latest-gpu-py3
RUN apt update -y && apt install -y \
libsm6 \
libxext6 \
libxrender-dev
RUN pip install \
opencv-python
@enric1994
enric1994 / extract.py
Created February 4, 2019 18:40
Extract frames from video and write file names in a file. Python
import cv2
output_folder = 'output'
output_file = 'frame.txt'
video_name = 'video.mp4'
import os
if not os.path.exists(output_folder):
os.makedirs(output_folder)