Skip to content

Instantly share code, notes, and snippets.

@dfbarrero
dfbarrero / animalsPolymorphism.py
Created March 13, 2020 11:11
Example of polymorphism in Python.
class Animal:
def __init__(self):
self.name = "Unknown"
self.age = 10
def describe(self):
print("Name: ", self.name)
print("Age: ", self.age)
def attack(self):
@dfbarrero
dfbarrero / animals.py
Last active March 13, 2020 10:53
Example of inheritance.
class Animal:
def __init__(self):
self.name = "Unknown"
self.age = 10
def describe(self):
print("Name: ", self.name)
print("Age: ", self.age)
class Dog(Animal):
@dfbarrero
dfbarrero / dogs.py
Last active March 13, 2020 09:57
Python OOP naive example.
class Dog:
def __init__(self):
self.name = "Unknown"
self.age = 10
def bit(self):
print(self.name + " has bitten")
def describe(self):
print("Name: ", self.name)
@dfbarrero
dfbarrero / onemax-ga.py
Last active February 23, 2022 17:57
Genetic Algorithm implemented with Inspyred to solve the one-max problem, with command-line argument parsing. Some evolution statistics are printed in stdout with CSV format, general info is printed in stderr.
""" Genetic Algorithm that solves the one-max problem.
Genetic Algorithm that solves the one-max problem, many parameters in the GA
can be changed by command line. This script has been designed for teaching
GA. Its code is based on the inspyred library examples.
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 3 of the License, or (at your option) any later
version.
@dfbarrero
dfbarrero / tunner.sh
Created September 27, 2019 08:58
Access a remote Jupyter notebook thorught a SSH tunnel in localhost
# On remote server
jupyter notebook --no-browser
# On local host
ssh -N -f -L localhost:8888:localhost:8889 remoteuser@remotehost
@dfbarrero
dfbarrero / astar.py
Last active March 26, 2019 08:22 — forked from jamiees2/astar.py
A* Algorithm implementation in Python 3.x.
# Enter your code here. Read input from STDIN. Print output to STDOUT
class Node:
def __init__(self,value,point):
self.value = value
self.point = point
self.parent = None
self.H = 0
self.G = 0
def move_cost(self,other):
return 0 if self.value == '.' else 1
#!/usr/bin/env python
""" Short description of this Python module.
Longer description of this module.
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 3 of the License, or (at your option) any later
version.
@dfbarrero
dfbarrero / gpl3-licence-header.c
Created March 10, 2019 10:39
Template of C header file with the GNU General Public License v3.
/*
* {{ proyect }}
*
* Copyright (C) {{ year }} {{ Organization }}
*
* File created by {{ author }}.
*
* File modified by {{ contributor }}.
*
* This program is free software: you can redistribute it and/or modify
@dfbarrero
dfbarrero / tips.txt
Last active April 1, 2020 20:39
ConsoleTips
cd $_ # $_ is the last argument given to the last command
cd - # - is the last folder
# Intall Jupyter support for conda environments
conda install nb_conda
conda install ipykernel
@dfbarrero
dfbarrero / encrypt-decrypt
Created February 22, 2019 09:41
Encryp and decrypt files in Linux with GPG
gpg -c file.txt
gpg -d file.txt.gpg