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
""" | |
Recursive search by file content. | |
By Juan C. Roldán (https://juancroldan.com/) | |
Just change WORDS to whichever strings you are looking for. | |
""" | |
from os import listdir | |
from os.path import isdir | |
WORDS = ["this is a test", "localhost"] |
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
<?php | |
$salt = "change_me"; | |
if (isset($_REQUEST["u"]) && isset($_REQUEST["k"]) && md5($_REQUEST["u"] . $salt) == $_REQUEST["k"]) { | |
$file_info = new finfo(FILEINFO_MIME_TYPE); | |
$res = file_get_contents($_REQUEST["u"]); | |
$mime_type = $file_info->buffer($res); | |
header('Content-type: '.$mime_type); | |
echo $res; |
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 PIL import Image | |
WIDTH = 700 | |
HEIGHT = 350 | |
img = Image.new('HSV', (WIDTH, HEIGHT)) | |
for x in range(WIDTH): | |
for y in range(HEIGHT): | |
if y < HEIGHT / 2: # white to rainbow |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width,initial-scale=1"> | |
<title>Project</title> | |
<link rel="stylesheet" href="style.css"> |
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 geopy.exc import GeocoderTimedOut | |
from geopy.geocoders import Nominatim | |
# Choose your preferred geocoder at http://geopy.readthedocs.io/en/latest/#module-geopy.geocoders | |
_geo = Nominatim() | |
def where(place, timeout=10): | |
res = None | |
while res == None: | |
try: |
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
# -- the cache snippet --------------------------------------------------------- | |
from os import makedirs | |
from os.path import exists, dirname | |
from pickle import load as pload, dump as pdump | |
from re import sub | |
from time import time | |
def cache(target, args, identifier=None, cache_life=3 * 24 * 3600): | |
""" Run the target function with the given args, and store it to a pickled |
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 os import listdir | |
from os.path import isdir | |
""" Find images with hidden compressed formats """ | |
ROOT = "path/to/a/folder/with/images" | |
IMAGE_EXTS = ["jpg", "png", "gif", "jpeg", "tiff", "svg", "bmp"] | |
EOF_SIGNATURES = { | |
"" | |
} |
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
# -- the dynamic programming snippet ------------------------------------------- | |
class DynProg: | |
""" Abstract class to solve problems using dynamic programming. To use it, | |
make a child class implementing alternatives, is_final and penalty. Then, | |
make one of such objects providing the initial state in the constructor, and | |
call to solve(), providing one search type. """ | |
ONE_SOLUTION = 0 | |
ONE_OPTIMAL_SOLUTION = 1 | |
ALL_SOLUTIONS = 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() |
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) |
OlderNewer