Skip to content

Instantly share code, notes, and snippets.

View MiguelPF's full-sized avatar
🎯
Focusing

Miguel Pousa MiguelPF

🎯
Focusing
  • Factorial
  • Barcelona, Spain
View GitHub Profile
@MiguelPF
MiguelPF / mixin.py
Created July 8, 2021 21:21
MixIn Decorator for Python (avoid circular dependencies by importing later)
def mixin(cls, mixinname: str, mixinmodule: str):
"""Mixes in the folling class.
Mixes in the methods defined in mixinname located in module mixinmdule.
This sidesteps the issue of circular dependencies by importing the dependencies
later on when the class is instantiated instead of in the global namespace.
With this decorator you avoid having to inherit from the mixins and you get
them at runtime.
Usage:
@MiguelPF
MiguelPF / ir.tesla.js
Created July 2, 2021 11:54
Set a notification to warn when tesla releases the Q2 deliveries number
Notification.requestPermission().then(function(result) {
console.log(result);
setInterval(function() {
if (document.querySelector('table.tcl-table tbody tr td:nth-child(3)').textContent.includes('Q2')) { var notification = new Notification('To do list', { body: 'q2' }); }
}, 10 * 1000); // 60 * 1000 milsec
});
@MiguelPF
MiguelPF / extract.py
Last active May 23, 2020 21:09
Extract all the classes in a Python project
import os
import logging
from pathlib import Path
from redbaron import RedBaron
class PythonProject:
def __init__(self, projectname):
self.projectname = projectname
self.numclasses = 0
0x586dc8C52c833a330777bEAC3A079a7B47AF824a
@MiguelPF
MiguelPF / Makefile
Created August 26, 2016 17:12
Example Makefile
TARGET_EXEC ?= a.out
BUILD_DIR ?= ./build
SRC_DIRS ?= ./src
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
@MiguelPF
MiguelPF / appspec.yml
Last active October 22, 2015 11:13
Code Deploy Examples
# This is an appspec.yml template file for use with AWS CodeDeploy.
# The lines in this template starting with the hashtag symbol are
# instructional comments and can be safely left in the file or
# ignored.
# For help completing this file, see the "AppSpec File Reference" in the
# "AWS CodeDeploy User Guide" at
# http://docs.aws.amazon.com/codedeploy/latest/userguide/app-spec-ref.html
version: 0.0
# Specify "os: linux" if this revision targets Amazon Linux,
# Red Hat Enterprise Linux (RHEL), or Ubuntu Server
@MiguelPF
MiguelPF / start-chef.sh
Created June 26, 2015 18:50
Chef beginnings
#
# Chef Recipe
#
#
sudo nano /etc/hosts
111.222.333.444 chef.domain.com chef
# where 111.222.333.444 is your chef server ip
hostname -f
@MiguelPF
MiguelPF / bernoulli.rb
Last active August 29, 2015 13:56
Bernoulli distribution
##
# Bernoulli of parameter p
# p should be a float between 0..1
def ber(p)
th = rand
return 0 if th < p
return 1 if th >= p
end
@MiguelPF
MiguelPF / imgToPoints.m
Created November 1, 2012 08:02
Medical 3D image to pcd
function [points]=imgToPoints(im,z)
xsize=size(im,1);
ysize=size(im,2);
points = zeros(xsize*ysize,6);
for i=1:xsize
for j=1:ysize
%point(1)=(i-1)*4; % 4mm x resolution
% if im(i,j,1)~=0
% disp([im(i,j,1) im(i,j,2) im(i,j,3)])
% end
@MiguelPF
MiguelPF / cloudToPcd.m
Created October 28, 2012 11:32
RGB-D Object to pcd format
function CloudToPcd(pcloud, filename)
% save point cloud to pcd format file
% only works with xyz pointclouds
pcdfile = fopen(filename, 'wt');
% Write the pcd header
fprintf(pcdfile, '%s\n', '# .PCD v.7 - Point Cloud Data file format');
% Write the pcd version
fprintf(pcdfile, '%s\n', 'VERSION .7');
fprintf(pcdfile, '%s\n', 'FIELDS x y z');