Skip to content

Instantly share code, notes, and snippets.

View soupglasses's full-sized avatar
🏳️‍🌈

Sofie soupglasses

🏳️‍🌈
View GitHub Profile
@soupglasses
soupglasses / baby-shark.py
Last active June 16, 2020 23:54
Challenge: Print baby shark with less than 300 characters of code.
def baby_shark_lyrics():
a,o=[],''
for s in 'Baby Mommy Daddy Grandma Grandpa'.split():
a+=[s+" shark"]
a+=["Let's go hunt"]
for i in a:
o+=(i+","+" doo"*6+"\n")*3+i+"!\n"
return o+'Run away,…'
print(baby_shark_lyrics())
@soupglasses
soupglasses / quadratic.py
Last active September 5, 2020 02:40
Quadratic formula solver using Python and Decimal precision for calculations
import click
from decimal import Decimal, getcontext
@click.command()
@click.argument('a', type=click.FLOAT)
@click.argument('b', type=click.FLOAT)
@click.argument('c', type=click.FLOAT)
@click.option('--precision', '-p', type=click.INT, help='Decimal precision by number')
def main(a,b,c,precision):
"""Quadratic formula solver"""
@soupglasses
soupglasses / fizzbuzz.py
Last active September 19, 2020 14:22
Fizzbuzz done with dictionary store and list comprehension
fizzbuzz_dict = {'Fizz': 3, 'Buzz': 5}
def fizzbuzz_gen(num: int) -> str:
"""Can easily change the values used at runtime from a dict."""
return ''.join(key * (num % value == 0) for key, value in fizzbuzz_dict.items()) or str(num)
def fizzbuzz_str(num: int) -> str:
"""About 3x faster than fizzbuzz_gen(), but no flexibility at runtime."""
return "Fizz" * (num % 3 == 0) + "Buzz" * (num % 5 == 0) or str(num)
@soupglasses
soupglasses / file_ext_fixer.py
Last active September 9, 2020 00:13
Fixes file extentions by reading the files content
"""
file_ext_fixer.py - https://gist.github.com/imsofi/dad85324d47b73fd7997d4e5673de645/edit
Usage:
Create a "photos" folder where the python file is located. Put all files
you want to try to fix into the "photos" folder.
Open a terminal window in the folder where this python file is located
and run: `python3 file_ext_fixer.py` or `python file_ext_finder.py`
(without the `)