Skip to content

Instantly share code, notes, and snippets.

View carlosplanchon's full-sized avatar
🎯
Focusing

Carlos A. Planchón carlosplanchon

🎯
Focusing
View GitHub Profile
import attrs
from attrs_strict import type_validator
import json5
from typing import Any, Optional
UNEXPECTED_END_OF_INPUT: str = "at column"
from enum import StrEnum, verify, UNIQUE, auto
#!/usr/bin/env python3
import attrs
import cattrs
import copy
import json
from typing import Any, Callable
@carlosplanchon
carlosplanchon / parse_broken_json.py
Created February 18, 2023 01:13
Code to parse the deepest object on a malformed JSON. It was created after seeing that GPT3's model text-davinci-003 sometimes return broken JSONs. Adapt it to your own needs.
#!/usr/bin/env python3
import decimal
import io
import json
import ijson
from typing import Any
@carlosplanchon
carlosplanchon / remove_python_comments.py
Last active May 4, 2022 00:34
Code to remove Python Comments.
#!/usr/bin/env python3
"""
Copyright <2022> <Carlos Andrés Planchón Prestes - Carlos Agustín Céspedes Vaucher>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
#!/usr/bin/env python3
from inspect import _empty, signature
def get_multiparameter_callback(callback, **parameters):
callback_sig_p = signature(callback).parameters
# If some provider parameter does not belong to callback parameters.
unexpected_parameters = list(parameters.keys() - callback_sig_p.keys())
if len(unexpected_parameters) > 0:
@carlosplanchon
carlosplanchon / Play YouTube song.
Created November 5, 2018 06:51
Plays a song from YouTube.
#!/usr/bin/env python3
import mps_youtube
def play_song_from_youtube(song_title, extra="lyrics HQ"):
"""It plays a song from YouTube."""
# It search the song based on title.
mps_youtube.commands.search.search(f"{song_title} {extra}")
# Setting encoder to OGG 256K
# Jobs configuration.
#
# Stores information about each job.
#
# NOTE: When having multiple jobs, both jobs will give the income payout to the player
# even if they give the pay for one action (make the configurations with this in mind)
# and each job will get the respective experience.
#
# e.g If player has 2 jobs where job1 gives 10 income and experience for killing a player
# and job2 gives 5 income and experience for killing a player. When the user kills a player
#!/usr/bin/env python3
import outfancy
m = outfancy.render.Chart()
m1 = 0.04
m2 = 0.01
m3 = 0.05
@carlosplanchon
carlosplanchon / velocitydemo.py
Last active March 11, 2016 21:44
A demo to show the velocity of Outfancy rendering (using Oneline).
#!/usr/bin/env python3
import outfancy
import random
import sys
motor = outfancy.render.Oneline()
color_list = ['\x1b[0;30m', '\x1b[0;31m', '\x1b[0;32m', '\x1b[0;33m', '\x1b[0;34m', '\x1b[0;35m', '\x1b[0;36m', '\x1b[0;37m', '\x1b[0;39m', '\x1b[0;40m', '\x1b[0;41m', '\x1b[0;42m', '\x1b[0;43m', '\x1b[0;44m', '\x1b[0;45m', '\x1b[0;46m', '\x1b[0;47m', '\x1b[0;49m', '\x1b[0;90m', '\x1b[0;91m', '\x1b[0;92m', '\x1b[0;93m', '\x1b[0;94m', '\x1b[0;95m', '\x1b[0;96m', '\x1b[0;97m', '\x1b[0;99m', '\x1b[0;100m', '\x1b[0;101m', '\x1b[0;102m', '\x1b[0;103m', '\x1b[0;104m', '\x1b[0;105m', '\x1b[0;106m', '\x1b[0;107m', '\x1b[0;109m', '\x1b[1;30m', '\x1b[1;31m', '\x1b[1;32m', '\x1b[1;33m', '\x1b[1;34m', '\x1b[1;35m', '\x1b[1;36m', '\x1b[1;37m', '\x1b[1;39m', '\x1b[1;40m', '\x1b[1;41m', '\x1b[1;42m', '\x1b[1;43m', '\x1b[1;44m', '\x1b[1;45m', '\x1b[1;46m', '\x1b[1;47m', '\x1b[1;49m', '\x1b[1;90m', '\x1b[1;91m', '\x1b[1;92m', '\x1b[1;93m', '\x1b[1;94m', '\x1b[1;95m', '\x1b[1;96m', '\x1b[1;97m', '\x1b[1;99m', '\x1b[1;100m', '\x
@carlosplanchon
carlosplanchon / funny_test2.py
Last active March 11, 2016 21:47
Another funny test with Outfancy
#!/usr/bin/env python3
import outfancy
import random
import sys
motor = outfancy.render.Table()
motor_oneline = outfancy.render.Oneline()
color_list = ['\x1b[0;30m', '\x1b[0;31m', '\x1b[0;32m', '\x1b[0;33m', '\x1b[0;34m', '\x1b[0;35m', '\x1b[0;36m', '\x1b[0;37m', '\x1b[0;39m', '\x1b[0;40m', '\x1b[0;41m', '\x1b[0;42m', '\x1b[0;43m', '\x1b[0;44m', '\x1b[0;45m', '\x1b[0;46m', '\x1b[0;47m', '\x1b[0;49m', '\x1b[0;90m', '\x1b[0;91m', '\x1b[0;92m', '\x1b[0;93m', '\x1b[0;94m', '\x1b[0;95m', '\x1b[0;96m', '\x1b[0;97m', '\x1b[0;99m', '\x1b[0;100m', '\x1b[0;101m', '\x1b[0;102m', '\x1b[0;103m', '\x1b[0;104m', '\x1b[0;105m', '\x1b[0;106m', '\x1b[0;107m', '\x1b[0;109m', '\x1b[1;30m', '\x1b[1;31m', '\x1b[1;32m', '\x1b[1;33m', '\x1b[1;34m', '\x1b[1;35m', '\x1b[1;36m', '\x1b[1;37m', '\x1b[1;39m', '\x1b[1;40m', '\x1b[1;41m', '\x1b[1;42m', '\x1b[1;43m', '\x1b[1;44m', '\x1b[1;45m', '\x1b[1;46m', '\x1b[1;47m', '\x1b[1;49m', '\x1b[1;90m', '\x1b[1;91m', '\x1b[1;92m', '\x1b[1;93m', '\x1b[1;94m', '\x1b[1;95m', '\x1b[1;96m', '\x1b[