Skip to content

Instantly share code, notes, and snippets.

View Linus-Albertus's full-sized avatar

Lino A. Urdaneta F. Linus-Albertus

View GitHub Profile
@Linus-Albertus
Linus-Albertus / vigenere.scala
Created September 9, 2021 12:30
[Vigenère] #Scala #BigBookPython #qu4nt
/* Vigenère Cipher, by Lino Urdaneta and Al Sweigart al@inventwithpython.com
The Vigenère cipher is a polyalphabetic substitution cipher that was
powerful enough to remain unbroken for centuries.
More info at: https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher
Tags: short, cryptography, math
*/
object Vigenere {
def main(): Unit = {
println("""Vigenère Cipher.
@Linus-Albertus
Linus-Albertus / bagels.scala
Last active September 7, 2021 20:50
[Bagels] #Scala #BigBookPython #qu4nt
/*Bagels, by Lino Urdaneta based in al@inventwithpython.com
A deductive logic game where you must guess a number based on clues.
View this code at https://nostarch.com/big-book-small-python-projects
A version of this game is featured in the book "Invent Your Own
Computer Games with Python" https://nostarch.com/inventwithpython
Tags: short, game, puzzle*/
object Main extends App {
from transformers import pipeline
classifier = pipeline('sentiment-analysis',
model="nlptown/bert-base-multilingual-uncased-sentiment")
sentences = ["¡Me encantan los artículos de Medium, son lo máximo!",
"Odio los lunes, no sirven para nada.",
"El libro es medio bueno; me gustaron algunos personajes."]
doc_review = nlp(review)
for sent in doc_review.sentences: # recorremos cada oración
for dep in sent.dependencies: # recorremos cada palabra
if dep[1] == 'amod': # el subíndice 1 indica que se trata de la clase funcional
print(dep[0].text, dep[2].text) # uso del atributo .text
@Linus-Albertus
Linus-Albertus / stanfordnlp_mod_phrase.py
Last active March 8, 2020 15:22
Mod Phrases in stanfordnlp
doc_review = nlp(review)
for sent in doc_review.sentences:
for dep in sent.dependencies:
if dep[1] == 'amod':
print(dep[0].text, dep[2].text)
@Linus-Albertus
Linus-Albertus / one_liner_conditional.py
Created July 19, 2019 22:45
[conditional one-liner] An one-liner conditional #python #conditional
y = 'high' if x > 6 else 'medium' if x == 6 else 'low'
@Linus-Albertus
Linus-Albertus / decorator.py
Created June 15, 2019 20:40
[python decorator] An example of a Python decorator #python #decorator
def decorator(inner_function):
def wrapper(*args, **kwargs):
# New wrapper stuff
inner_function(*args, **kwargs)
# New wrapper stuff
return inner_function(*args, **kwargs)
return wrapper
@decorator
def decorated_function():
@Linus-Albertus
Linus-Albertus / items_freqs_dict.py
Created June 5, 2019 12:01
[item freqs dictionary] Add an item / frequency to a dictionary #dict
items_list = [a, b, b, c, c, c]
for i in items_list:
items_list.setdefault(i, 0)
items_list[i] += 1
@Linus-Albertus
Linus-Albertus / iterate_dict.py
Created June 5, 2019 02:01
[iterate dictionary] Iterate a Python dict
dictionary = {'a': 1, 'b': 2, 'c': 3}
for k, v in dictionary.items():
print(k, v)
@Linus-Albertus
Linus-Albertus / zipping_lists.py
Created May 26, 2019 13:00
[zipping elements to dict] Zipping two or more elements from two lists and create a dictionary #python #zip
keys = ['a', 'b', 'c']
values = [1, 2, 3]
zipped_dict = dict(zip(keys, values))