Skip to content

Instantly share code, notes, and snippets.

View unacceptable's full-sized avatar
👑
Strange women lying in ponds distributing swords is no basis for a system of ...

Robert J. unacceptable

👑
Strange women lying in ponds distributing swords is no basis for a system of ...
View GitHub Profile
'''
Elegant hourglass pattern generator.
'''
import itertools
def hourglass(n: int, char: str = "*") -> str:
'''
Generate an hourglass pattern.
from functools import lru_cache
@lru_cache(maxsize=None)
def fibonacci(n: int) -> int:
'''
Return the n-th Fibonacci number.
'''
if n == 0:
return 0
#!/usr/bin/env bash
set -e
git diff | git apply --whitespace=fix
git diff --cached | git apply --cached --whitespace=fix
def pi(n_terms: int) -> float:
'''
Approximate pi using the Leibniz formula
'''
series = [
(-1)**k / (2*k + 1) for k in range(n_terms)
]
pi_approx = 4*(
sum(series)
#!/usr/bin/env python3
'''
Generate a graph of the real returns of the S&P 500
'''
import logging
import yfinance as yf
import pandas as pd
import requests
# macos
ssh-keygen -t rsa -b 4096 -E SHA512 -m PEM -f ~/my.jwt.RS512.pem
# pip install pyjwt
python <<PYTHON
import os
import logging
import jwt
#!/usr/bin/env python
'''
Calculate AWS Fargate pricing
'''
import argparse
import logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s %(levelname)s %(message)s'
#!/usr/bin/env python
'''
Convert an image to ASCII art
'''
import argparse
from PIL import Image
# pylint: disable=redefined-outer-name
def main(args):
'''
#!/usr/bin/env python
'''
.. ::
.:.:=;.
.: ;;;. .
...=:;:..:?:.:.
.;;=;=====;;*=.
..::;;;========;?=.
.;;;;;;=======;==;.
.:;;;;;;==**==?SSZ;
#!/usr/bin/env bash
set -e
watch_dns(){
HOST=$1
DNS_SERVER=${2:-"8.8.8.8"}
OLD_IP="$(dig +short "$HOST")"
echo "$(date) Starting to watch $HOST for changes from \"$OLD_IP\" as tracked by ${DNS_SERVER}"