Skip to content

Instantly share code, notes, and snippets.

View s-m-e's full-sized avatar
🌍
on planet earth, galactic sector zz plural z alpha

sme s-m-e

🌍
on planet earth, galactic sector zz plural z alpha
View GitHub Profile
@s-m-e
s-m-e / svg_text_length.py
Last active July 27, 2021 00:47
A Python (3) class for figuring out the width and height of a formatted svg text.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Loosely based on http://stackoverflow.com/a/28741636/1672565
import subprocess
import struct
import os
@s-m-e
s-m-e / run_routines_on_objects_in_parallel_and_return.py
Last active September 16, 2017 19:38
Multiprocessing pool: How to call an arbitrary list of methods on a list of class objects
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# LIBRARY PART
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
from functools import partial
import multiprocessing
NUM_CORES = multiprocessing.cpu_count()
@s-m-e
s-m-e / daemonocle_status_check.py
Created December 1, 2017 11:37
Script for programmatically checking weather a daemonocle daemon is up or down
# Script for programmatically checking weather a daemonocle daemon is up or down
# -> see: https://github.com/jnrbsn/daemonocle
# -> works around the following issue: https://github.com/jnrbsn/daemonocle/issues/18
# -> requires knowledge of the location of the daemon's pid file
# -> tested with CPython 3.6
# Licenced under the MIT License (MIT)
# Copyright (c) 2017 @s-m-e
import os
@s-m-e
s-m-e / download_github_organization_stats.py
Created January 5, 2020 09:55
Download basic statistics for all repositories in list of GitHub organizations
#!/usr/bin/env python
# Python 3
import datetime
import json
import os
from github import Github # pip install PyGithub
ORGANIZATIONS = ['my_organization', 'some_other_organization']
@s-m-e
s-m-e / download_pypi_package_stats.py
Last active January 5, 2020 10:04
Download PyPI statistics for all packages of one user (maintainer and/or owner)
#!/usr/bin/env python
# Python >= 3.6
import datetime
import json
import os
import xmlrpc.client
import requests # pip install requests
@s-m-e
s-m-e / download_www_logs_from_hetzner.py
Created January 5, 2020 10:10
Download & updating "www_logs" from Hetzner's web hosting service (for cron jobs)
#!/usr/bin/env python
# Python 3
import datetime
import gzip
import os
import stat
import pysftp # pip install pysftp==0.2.8
@s-m-e
s-m-e / cairo_test.py
Last active September 26, 2023 17:59
A simple script for generating individual frames of an animation
import cairo
import math
import os
class Image:
def __init__(self, width, height, background_color = (1.0, 1.0, 1.0)):
self._width, self._height = width, height
self._surface = cairo.ImageSurface(cairo.FORMAT_RGB24, self._width, self._height)
self._ctx = cairo.Context(self._surface)
self._set_background_color(background_color)
@s-m-e
s-m-e / poliastro_benchmark.ipynb
Last active September 3, 2020 14:05
poliastro benchmark
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@s-m-e
s-m-e / mptest.py
Last active August 22, 2021 09:41
multiprocessing pool test, process-based and thread-based
# -*- coding: utf-8 -*-
# QGIS 3.x / Python 3.x
from math import sqrt, ceil
from multiprocessing import Pool, Process, Queue
from multiprocessing.pool import ThreadPool
WORKERS = 2
def worker_task(number):
from bewegung import Video, FFmpegGifEncoder
from multiprocessing import cpu_count
from random import gauss
FRAMES = 300
def data(length, *args, **kwargs):
state = 0
for _ in range(length):