Skip to content

Instantly share code, notes, and snippets.

@Eitol
Eitol / gist:7fe6957d2ae58665a28438fc4ae9c29e
Created March 14, 2017 16:22
Return the system timezone in linux
@staticmethod
def get_system_timezone() -> str:
"""
Retorna el timezone del sistema
:return: Ej: America/Caracas
"""
str_timezone = subprocess.getoutput('ls /etc/ -l | grep localtime | awk \'{print $11}\'')
assert str_timezone is not None and len(str_timezone) and \
str_timezone.find('../usr/share/zoneinfo/') != -1, "TIMEZONE_GET_ERROR:"
str_timezone = str_timezone.replace('../usr/share/zoneinfo/', '')
@Eitol
Eitol / view_names.py
Created March 17, 2017 17:15
View names of all Views CouchDB in Python
_db = couchdb.Server("http://user:miclave_loca@192.168.1.250:5984/")['base_de_datos_loca']
def get_all_views(db: couchdb.Server) -> list:
views_raw = _db.view('_all_docs', startkey="_design/", endkey="_design0", include_docs=True)
return [view.id.split('/')[1] for view in views_raw.rows]
return views
if __name__ == '__main__':
print(get_all_views(_db))
@Eitol
Eitol / merge_mio.py
Created June 4, 2017 13:20
Merge sort using queues made in python3
from collections import deque
def merge_sort(v: list) -> list:
if len(v) < 2:
return v
middle = int(len(v) / 2)
left = deque(merge_sort(v[:middle]))
right = deque(merge_sort(v[middle:]))
out = []
@Eitol
Eitol / install_kivy.sh
Created February 15, 2018 05:02
Install Kivy 1.10.0 in Raspbian Strech (9)
#!/usr/bin/env bash
sudo apt-get update
apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev \
pkg-config libgl1-mesa-dev libgles2-mesa-dev \
python-setuptools libgstreamer1.0-dev git-core \
gstreamer1.0-plugins-{bad,base,good,ugly} \
gstreamer1.0-{omx,alsa} python-dev libmtdev-dev \
xclip xsel libatlas-base-dev
pip3 install Cython==0.27.3 kivy==1.10.0
sudo apt remove minecraft-pi chromium-browser claws-mail galculator bluej greenfoot geany scratch scratcht2 sense-emu-tools sense-hat libreoffice* wolfram*
@Eitol
Eitol / install_avrdude_raspbian9.sh
Created March 2, 2018 03:46
Install AVRDUDE in Raspbian 9 (raspberry pi model B)
#!/usr/bin/env bash
sudo apt-get install bison flex libusb-dev gcc gcc-avr avr-libc libelf-dev libusb-1.0-0-dev libusb-1.0-0-dev libftdi1-dev libftdi-dev libhidapi-libusb libevent-pthreads-2.0-5 libpthread-workqueue0 -y
wget http://ftp.nchc.org.tw/Unix/NonGNU/avrdude/avrdude-6.1.tar.gz
tar xfv avrdude-6.2.tar.gz -C /tmp
CURRENT_DIR=$(pwd)
cd /tmp/avrdude-6.2
./configure --enable-linuxgpio
make -j4
sudo make install
@Eitol
Eitol / pytest_mock_example.py
Created April 13, 2018 02:34
mock pytest parametrize test
# first install pip3 install pytest-mock
import os
import pytest
class TestNodeInteractor:
    def exists(self, path):
        return os.path.exists(path)
    @pytest.fixture(autouse=True)
    def mock_exists(self, mocker, expect):
@Eitol
Eitol / asdadasdsad
Created October 7, 2018 12:57
run pgadmin #postgres
python3 /usr/local/lib/python3.6/dist-packages/pgadmin4/pgAdmin4.py
@Eitol
Eitol / asdasdasd
Last active October 7, 2018 13:19
django cli #django
pip3 install virtualenv
pip install psycopg2-binary
# Iniciar un proyecto
django-admin.py startproject NOMBRE
# La wea que migra
manage.py makemigrations
manage.py migrate
manage.py runserver
@Eitol
Eitol / install_protobuf.sh
Last active November 14, 2018 12:48
Install lastest version of protobuf. Tested in in ubuntu 18.04.
#!/usr/bin/env bash
# run like:
# sudo -S bash ./install_protobuf.sh
#-------- Config ---------
SO=linux-x86_64 # linux-x86_64 | linux-x86_32 | windows | osx
PROTOBUF_REPO="protocolbuffers/protobuf"
PROTOBUF_USER=`whoami`