Skip to content

Instantly share code, notes, and snippets.

View HemersonTacon's full-sized avatar

Hemerson Tacon HemersonTacon

View GitHub Profile
@HemersonTacon
HemersonTacon / user.postfixTemplates
Last active April 12, 2022 14:13
Postfix templates for PyCharms plugin "Custom Postfix Templates"
.var : New variable
ANY → $var$ = $expr$
.str : Cast to string
ANY → str($expr$)
.fstr : Apply f-string formatting
ANY → f"{$expr$}"
.list : Cast to list
@HemersonTacon
HemersonTacon / wordle_solver.py
Last active January 29, 2022 14:11
wordle/term.ooo solver
from string import ascii_lowercase
import argparse
def letter_frequency_builder(words_list):
corpus_length = len(words_list)
return {letter: sum(letter in word for word in words_list)/corpus_length for letter in ascii_lowercase}
def word_score(word, letter_frequency):
@HemersonTacon
HemersonTacon / is_prime.py
Created October 23, 2020 16:49
Find out if a number is prime with regex
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 23 17:34:25 2020
@author: hemerson.tacon
"""
import re
@HemersonTacon
HemersonTacon / rainy_valleys.py
Last active March 11, 2020 14:32
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 9 22:51:09 2020
Given n non-negative integers representing an elevation map where the width
of each bar is 1, compute how much water it is able to trap after raining.
@author: Hemerson Tacon
"""
import os
import matplotlib.pyplot as plt
def plot_and_save(history, name, show_plots=False, folder="imgs"):
"""
Create a charts comparing accuracy and loss of training and validation
phases for each epoch
Args:
history (Hisotry): The History object returned from a fit function
@HemersonTacon
HemersonTacon / keras_model_regularization.py
Last active August 24, 2018 16:54
Generic function to apply kernel regularization to any keras model layer that supports it
from keras.regularizers import l1_l2
def set_kernel_reg(model, lambdal1 = 0, lambdal2 = 0):
"""
Apply kernel regularization to keras model
Args:
model: Instance of `Model` not compiled yet
lambda1 (float): L1 regularization factor
lambda2 (float): L2 regularization factor