This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from folium import Map, Marker, Popup | |
from os import listdir | |
from os.path import isfile | |
from piexif import load | |
from PIL import Image | |
from PIL.ExifTags import GPSTAGS, TAGS | |
from pillow_heif import read_heif | |
EXTENSIONS = {'jpg', 'jpeg', 'jfif', 'gif', 'png', 'webp', 'heic'} | |
PATH = 'your/path/here' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* See in action at https://codepen.io/juancroldan/pen/vYVLYBx */ | |
.polaroid { | |
background: #eeefea; | |
box-shadow: 0 0 .5px 1px #5415; | |
border-radius: 3px; | |
} | |
.polaroid img { | |
width: 230px; | |
height: 305px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <filesystem> | |
#include <thread> | |
#include <mutex> | |
#include <queue> | |
#include <condition_variable> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask.helpers import request | |
from traceback import format_exc | |
SERVER = Flask(__name__) | |
PORT = 5000 | |
# SSL_CONTEXT = '/etc/ssl/certificate.crt', '/etc/ssl/private.key' | |
SSL_CONTEXT = None | |
def api(data: dict): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' TABBER: Because spaces suck | |
This script will recursively convert all files in its directory from space indented to tab indented. | |
It will detect the number of spaces used for indentation and transform them into tabbed files. | |
Usage: | |
1. Copy the directory you want to convert and put this file inside. If you're brave enough, skip the | |
copying part. | |
2. Review the EXTENSIONS and IGNORE_FILES values. | |
3. Run it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WEEK_DAYS = 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun' | |
def weekday(day: int, month: int, year: int) -> str: # You'd rather operate with datetimes, but this is funnier. | |
''' Computes the day of the week using Zeller's Congruence. ''' | |
year_shift = year + year // 4 - year // 100 + year // 400 | |
return WEEK_DAYS[(5 + day + (13 * (month + 1)) // 5 + year_shift) % 7] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, send_file, request | |
from hashlib import sha256 | |
from os import listdir | |
from os.path import join, abspath, dirname, isdir | |
from sys import stderr | |
app = Flask(__name__) | |
template = '<!doctype html><head><meta charset="utf-8"><title>%s</title></head><body><h1>%s</h1><ul>%s</ul></body></html>' | |
base = abspath('.') | |
salt = 'changeme' # generated with https://www.random.org/passwords/?num=1&len=24&format=html&rnd=new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import timedelta | |
from requests import get | |
from time import time | |
from sys import stdout | |
def bytes_to_human(size, decimal_places=2): | |
for unit in ["", "k", "M", "G", "T", "P", "E", "Z", "Y"]: | |
if size < 1024: break | |
size /= 1024 | |
return "%s%sB" % (round(size, decimal_places), unit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt, ceil | |
from itertools import zip_longest, compress, chain, product, combinations | |
from functools import reduce | |
def prime_sieve(n): | |
""" | |
Returns: list of primes, 2 <= p < n | |
Performance: 0.5s for 10**7, 5s for 10**8, 69s for 10**9 | |
""" | |
sieve = [True] * int(n / 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from smtplib import SMTP | |
def send_gmail(to, subject, text, username="********@gmail.com", password="********"): | |
""" Send a mail using simple SMTP. """ | |
server = SMTP('smtp.gmail.com:587') | |
server.starttls() | |
server.login(username, password) | |
msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n%s"%(username, to, subject, text) | |
server.sendmail(username, to, msg) | |
server.quit() |
NewerOlder