Skip to content

Instantly share code, notes, and snippets.

View knasiotis's full-sized avatar

Konstantinos Nasiotis knasiotis

View GitHub Profile
@Ze1598
Ze1598 / centered_text.py
Last active October 11, 2021 22:37
Create images with centered text (PIL)
from PIL import Image, ImageDraw, ImageFont
from textwrap import wrap
def get_y_and_heights(text_wrapped, dimensions, margin, font):
"""Get the first vertical coordinate at which to draw text and the height of each line of text"""
# https://stackoverflow.com/a/46220683/9263761
ascent, descent = font.getmetrics()
# Calculate the height needed to draw each line of text (including its bottom margin)
line_heights = [
@errrzarrr
errrzarrr / ex.sh
Created May 1, 2020 02:07
ex - archive extractor
# put this into your ~/.bashrc file
# or ~/.bash_functions file
#
# # ex - archive extractor
# # usage: ex <file>
ex () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
@gabrielgarza
gabrielgarza / evolve.py
Last active October 8, 2018 19:58
Simple Genetic Algorithm
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import random
class Individual(object):
def __init__(self, numbers=None, mutate_prob=0.01):
if numbers is None:
self.numbers = np.random.randint(101, size=10)
/**
* This Google Sheets script keeps data in the specified column sorted any time
* the data changes.
*
* After much research, there wasn't an easy way to automatically keep a column
* sorted in Google Sheets, and creating a second sheet to act as a "view" to
* my primary one in order to achieve that was not an option. Instead, I
* created a script that watches for when a cell is edited and triggers
* an auto sort.
*