Skip to content

Instantly share code, notes, and snippets.

View alexvicegrab's full-sized avatar

Sasha (Alejandro Vicente Grabovetsky) alexvicegrab

View GitHub Profile
@alexvicegrab
alexvicegrab / coloured_parser.py
Created February 9, 2018 14:28
Colourise the information encoded in the parser
#! /usr/bin/env python
"""
Parser will be colourised using ANSI colors via "blessings" library
Calling:
$ python ./parser.py --help
Will show the help printed in a different colour:
$ python ./parser.py options --foo sausage --bar egg
Will display the argument namespace in colour
"""
@alexvicegrab
alexvicegrab / template_parser.py
Last active February 9, 2018 14:06
Python argparse with either a template or options
#! /usr/bin/env python
"""
If template file "template.conf" contains:
["--foo", "sausage", "--bar", "egg"]
Calling:
$ python ./parser.py template template.conf
Will be equivalent to calling:
$ python ./parser.py options --foo sausage --bar egg
And the initial option we attach to the parser needs to appear before the command:
Verifying that "alexvicegrab.id" is my Blockstack ID. https://onename.com/alexvicegrab
@alexvicegrab
alexvicegrab / Calvin_lights.py
Last active April 7, 2021 09:41
Solution to Calvin traffic light puzzle
#! /usr/bin/env python
# Calvin has to cross several signals when he walks from his home to school.
# Each of these signals operate independently.
# They alternate every 80 seconds between green light and red light.
# At each signal, there is a counter display that tells him how long it will be before the current signal light changes.
# Calvin has a magic wand which lets him turn a signal from red to green instantaneously.
# However, this wand comes with limited battery life, so he can use it only for a specified number of times.
#
# a. If the total number of signals is 2 and Calvin can use his magic wand only once, then what is the expected waiting
@alexvicegrab
alexvicegrab / kodi_controller.py
Last active December 21, 2016 18:29
Simple remote controller for Kodi player
#! /usr/bin/env python
import curses
import os
import sys
from socket import *
from kodi.xbmcclient import * # You may need to install the kodi xbmc client
from blessings import Terminal # Not strictly necessary, but for printing warning messages in colour
t = Terminal()