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
def histogram(in_list): | |
hist = [[0] * len(in_list) for _ in range(max(in_list))] | |
for i in range(len(hist)): | |
for j, val in enumerate(in_list): | |
if val > i: | |
hist[i][j] = 1 | |
out_str = '' | |
for subl in hist[::-1]: | |
for val in subl: | |
if val: |
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
## Python syntax highlighting rules for Nano | |
## The colors chosen here may seem strange. | |
## In my terminal, "yellow" = orange, "magenta" = purple, "brightyellow" = yellow, "cyan" = teal. | |
## Since there is no actual magenta, I used "brightred" which is the closest I could get. | |
## Since there is no grey, black is difficult to read in a terminal and setting the background to | |
## white is harsh on the eyes, I decided to use teal for comments. | |
syntax "python" "\.py$" | |
header "^#!.*/(env +)?python[-0-9._]*( |$)" | |
magic "Python script" |
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
import string | |
import random | |
vowels = 'aeiouy' | |
consonants = list(set(string.ascii_lowercase).difference(set(vowels))) | |
def generate_name(): | |
name = '' | |
consecutive_consonants = 0 | |
for i in range(random.randint(3, 10)): | |
new_letter = random.choice(string.ascii_lowercase) |
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
import PyPDF2 as PDF | |
import sys | |
def pdf_cat(allPdfFiles): | |
merger = PDF.PdfFileMerger(strict=False) | |
for filename in allPdfFiles: | |
merger.append(PDF.PdfFileReader(filename, strict=False)) |
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 pygments import highlight | |
from pygments.lexers import get_lexer_by_name | |
from pygments.formatters import BBCodeFormatter | |
import re | |
import sys | |
def get_comments(code): | |
""" Extracts comments and docstrings from python code. |
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
import sys | |
from numpy import argmax | |
translate = { | |
'I': 1, | |
'V': 5, | |
'X': 10, | |
'L': 50, | |
'C': 100, |
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
import sys | |
from math import ceil | |
from hsv_to_rgb import hsv_to_rgb | |
from rgb_to_hsv import rgb_to_hsv | |
def compress_color(pixel, level=16): | |
""" Compresses color by a specified factor. | |
Compressed colors are rounded up. |
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
def hsv_to_rgb(pixel): | |
""" converts a pixel expressed in RGB to an HSV expression | |
see https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB | |
Args: | |
pixel<(h, s, v)>: | |
h <float[0-360]>: hue | |
s <float[0-1]>: saturation | |
v <float[0-1]>: "value" (brightness) | |
Return: | |
r <int[0-255]>: red value |
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
import sys | |
# values for 0-9 a-z as specified in the comic, with an additional 0 for | |
# unrecognized characters. | |
values = [60, -74, 6, 55, 35, 74, 6, -58, -67, -37, -14, -5, 27, -21, -45, 5, | |
27, -44, -21, 64, 32, 12, 19, -46, -80, -27, 40, 8, 15, -18, -68, | |
41, -20, 126, -90, 83, 0] | |
def to_index(c): | |
""" Determines the index to look at in the `values' list given a character c |
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
# Garbage matcher | |
# matches any string consisting of only |, <, >, +, *, ^, #, =, and hyphen chains. | |
# this is to identify patterns like ++<===> ######## <---->^^ which serve no purpose but to decorate the text | |
/(\||(--+)|(__+)|<|>|\+|\*|\^|#|=|~)+|(\\|_|\/){2,}/ | |
# Garbage matcher 2 | |
# matches anything that isn't a letter, space or basic punctuation. | |
# this is typically useful for cleaning up emojis | |
/.(?<!([a-zA-Z0-9]|,|\.|'| |\?|\!))/ |
NewerOlder