This file contains hidden or 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
package logging | |
import ( | |
"io" | |
"log" | |
"os" | |
) | |
type Logger struct { | |
Info *log.Logger |
This file contains hidden or 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
import ahocorasick # pip install pyahocorasick | |
""" | |
See: http://ieva.rocks/2016/11/24/keyword-matching-with-aho-corasick/ | |
""" | |
def make_aho_automaton(keywords): | |
a = ahocorasick.Automaton() # initialize | |
for (key, cat) in keywords: |
This file contains hidden or 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
""" | |
This code is based on https://github.com/AzadKurt/pexif written by AzadKurt | |
""" | |
def remove_exif(img_bytes: bytes) -> bytes: | |
""" | |
returns the bytes of the image without exif | |
:param img_bytes: image bytes including exif |
This file contains hidden or 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
import io | |
import os | |
from PIL import Image | |
from PIL.JpegImagePlugin import JpegImageFile | |
class Orientation: | |
key = 0x0112 # see: PIL.ExifTags.TAGS | |
flip_horizontal = 2 |
This file contains hidden or 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
import io | |
import json | |
class Ascii: | |
quote = ord('"') | |
backslash = ord('\\') | |
comma = ord(',') | |
colon = ord(':') |
This file contains hidden or 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
import datetime | |
from operator import itemgetter | |
from pprint import pprint | |
import boto3 | |
def chunks(lst, n): | |
"""Yield successive n-sized chunks from lst.""" | |
for i in range(0, len(lst), n): |
This file contains hidden or 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 contextlib import contextmanager | |
import dask.dataframe as dd | |
import pyarrow # noqa | |
from dask.distributed import Client, LocalCluster | |
""" | |
Don't let `total_memory_limit` exceed your memory. | |
This script will aborts, if runtime memory usage exceeds `total_memory_limit` | |
In my experience, it works for me: |
This file contains hidden or 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
package main | |
import ( | |
"errors" | |
"io" | |
"os" | |
) | |
type ImageSize struct { | |
Width int |
This file contains hidden or 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
package main | |
import ( | |
"bufio" | |
"encoding/csv" | |
"encoding/json" | |
"os" | |
) | |
func main() { |
This file contains hidden or 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
import csv | |
import json | |
import sys | |
import os.path | |
import tqdm | |
def main() -> int: | |
if len(sys.argv) == 2: | |
in_filename = sys.argv[1] |