Skip to content

Instantly share code, notes, and snippets.

@juanluisrto
juanluisrto / calculadora_impuestos.py
Created July 12, 2023 10:08
Función para estimar el irpf a pagar en España, teniendo en cuenta los tramos
def calculadora_impuestos(ingresos):
irpf_escalones = {
12_450 : 0.19,
20_200 : 0.24,
35_200 : 0.30,
60_000 : 0.37,
300_000 : 0.45,
1e100 : 0.47
}
@juanluisrto
juanluisrto / subscription_killer.js
Created December 1, 2022 20:54
Getting rid of adblocker registration request for newspapers
javascript:(function(){
document.querySelectorAll(".fc-dialog-container, .fc-dialog-overlay").forEach(e => {e.style.setProperty("display", "none", "important");});
document.body.style.overflow = "visible";
})()
// Add this as a bookmark to your bookmark bar
from math import atan2, degrees, radians, sin, cos
def fit_text_as_geometry_between_two_points(text, A, B):
mid_coords = ((B[1] + A[1])/2, (B[0] + A[0])/2)
angle = atan2(B[1] - A[1], B[0] - A[0])
bbox = LineString([A,B]).bounds
h = get_height(bbox)
w = get_width(bbox)
scale_factor = 100*(abs(h*sin(angle)) + abs(w*cos(angle)))
ml = text_as_geometry(text, mid_coords, scale_factor, degrees(angle))
return ml
import numpy as np, pandas as pd
import freetype
from shapely.geometry import *
from shapely import affinity as aff
from cartoframes.viz import Layer
face = freetype.Face("Vera.ttf") # path to your font
face.set_char_size(3000, hres = 100)
# These parameters are ok for Vera, but should be adjusted for each font.
char_width = 1500
@juanluisrto
juanluisrto / drawcircle_oneliner.py
Last active July 28, 2022 12:04
Draw a circle with ascii art in one line
deadly_one_liner = (
lambda r, n : print("".join(
["00"
if any((i == p[0] and j == p[1] for p in
(lambda r, n : [
[round((lambda x : 1 - (x**2)/2 + x**4/(4*3*2) - x**6/(6*5*4*3*2))(2*3.1415/n*x)*r + n/2),
round((lambda x : x - (x**3)/6 + x**5/(5*4*3*2) - x**7/(7*6*5*4*3*2))(2*3.1415/n*x)*r + n/2)]
for x in range(-int(n/2),int(n/2))])(r,n)))
or (i == round(n/2) and j < n) or j == round(n/2)
or i == j or i == n - j
@juanluisrto
juanluisrto / generate_fake_dataframe.py
Last active June 17, 2023 05:37
Function which generates dataframes with fake data in a controlled manner.
import pandas as pd
import numpy as np
from itertools import cycle
def generate_fake_dataframe(size, cols, col_names = None, intervals = None, seed = None):
categories_dict = {'animals': ['cow', 'rabbit', 'duck', 'shrimp', 'pig', 'goat', 'crab', 'deer', 'bee', 'sheep', 'fish', 'turkey', 'dove', 'chicken', 'horse'],
'names' : ['James', 'Mary', 'Robert', 'Patricia', 'John', 'Jennifer', 'Michael', 'Linda', 'William', 'Elizabeth', 'Ahmed', 'Barbara', 'Richard', 'Susan', 'Salomon', 'Juan Luis'],
'cities' : ['Stockholm', 'Denver', 'Moscow', 'Marseille', 'Palermo', 'Tokyo', 'Lisbon', 'Oslo', 'Nairobi', 'Río de Janeiro', 'Berlin', 'Bogotá', 'Manila', 'Madrid', 'Milwaukee'],
'colors' : ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'purple', 'pink', 'silver', 'gold', 'beige', 'brown', 'grey', 'black', 'white']
}
@juanluisrto
juanluisrto / sum_of_rolling_dice.py
Created July 16, 2021 15:30
Probability of the sum of n dice rolls with three different methods
import math, numpy as np
from math import factorial as fact
import statistics as stats
def prob_of_sum_gaussian(s,n):
mean = 3.5*n
std = np.sqrt(n*105/36)
normal_dist = stats.NormalDist(mean, std)
return normal_dist.pdf(s)
@juanluisrto
juanluisrto / rotating_ip_proxy_checker.py
Created November 2, 2020 00:00
Check wether your rotating ip proxy server is working
proxy = "IP:PORT"
http_proxy = "http://" + proxy
https_proxy = "https://"+ proxy
ftp_proxy = "ftp://"+ proxy
proxyDict = {
"http" : http_proxy,
"https" : https_proxy,
"ftp" : ftp_proxy
}
@juanluisrto
juanluisrto / import_file_at_path.py
Created October 29, 2020 16:44
Import a file at a given path with autoreload
%load_ext autoreload
%autoreload 2
import sys, os
file_path = r"\path\to\file.py"
path = os.path.dirname(file_path)
sys.path.append(path)
from file import *
@juanluisrto
juanluisrto / conda2jupyter.sh
Last active July 27, 2022 15:48
Using conda environment in jupyter notebook
# run from the environment you want to add to jupyter.
# --name myenv is just the internal name ipykernel gives to the kernel
source activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"