Skip to content

Instantly share code, notes, and snippets.

View taikedz's full-sized avatar

Tai Kedzierski taikedz

View GitHub Profile
@taikedz
taikedz / pyodide-example.html
Last active May 20, 2022 14:39
Example of using python directly in a HTML page with DOM access
<!DOCTYPE html>
<html><head>
<style>
python { display: none; }
</style>
<script src="https://cdn.jsdelivr.net/pyodide/v0.20.0/full/pyodide.js"></script>
<script>
// https://pyodide.org/en/stable/usage/quickstart.html
pyscripts = document.getElementsByTagName("python");
let pyodide = null
@taikedz
taikedz / .bashrc
Last active May 12, 2022 16:37
Turn off Groovy Java Reflection Warnings
# ... add this to your bashrc to turn off those pesky warnings when running Groovy
# From https://github.com/apache/groovy/commit/a7f7cdd352a40dd7acd2def999eb560c2b76904e
# Via https://dev.to/erichelgeson/removing-illegal-reflective-access-warnings-in-grails-4-393o
_java_opens=(
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.lang.annotation=ALL-UNNAMED
--add-opens=java.base/java.lang.invoke=ALL-UNNAMED
--add-opens=java.base/java.lang.module=ALL-UNNAMED

Easy Custom Logger

The default setup for the logging utility is a little unwieldy to set up for every project - though once done, it is likely to seldom change.

This snippet provides a pre-configured global logging utility allowing for a log level to be set via environment variable, as well as a pretty-print dump() log function that writes when level is set to DEBUG.

By default, logging goes to stdout, but can be redirected to a file.

@taikedz
taikedz / README.md
Created January 31, 2022 12:19
Kill unkillable Jenkins job

Kill unkillable Groovy job

If a job is running a system groovy script, it cannot be simply "aborted"

You need to go to $jenkins_url/script and run the contents of the attched script, replacing the original job_line content with the path (from URL) of your job

@taikedz
taikedz / decorator_example.py
Last active January 10, 2022 11:13
Python Decorator Example
"""
A Python decorator is a special function that can be added above a
callable definition (function, class, anything that implements the
`__call__()` method)
When a decorated function is called, it is in fact the decorator
itself that is called, and the wrapped callable is then normally
called by the implementing handler of the decorator.
A Python decorator is comprised of 3 parts:
@taikedz
taikedz / README.md
Created December 8, 2021 17:17
Download Love2d.org's principal wiki documentation pages.

Love2D.org/wiki downloader

The Love2D wiki is a great starting resource. Mostly I do small-time game development for fun, on long flights or train journeys, or out in remote places. Frankly, it's the only time when I am guaranteed time to not be disturbed for sufficiently long periods.

And so, I need the main wiki in local, offline, usable format.

This script is a considereate slurper which shouldn't DoS the server in the slightest.

@taikedz
taikedz / README.md
Last active November 18, 2021 15:40

Plot times examples

As a network behaviour demonstration, I did a repeated clone-out of a Git repository, writing its timestamp data with date '+%F %T' in columns one and two (start and end times) of a CSV

This Python script processes that CSV to produce a plot of the durations:

  • timedeltas calculated using datetime
  • plotting using matplotlib.pyplot
  • adding labels at spaced out intervals, and rotated
@taikedz
taikedz / rename-tracks.py
Created September 7, 2021 11:44
Tool to rename tracks
""" Rename files
rename-tracks.py TRACKFILE [apply]
TRACKFILE is a basic text file, each line containing a track name.
This script naively looks for the track name in each file name.
If found, the old file name and new file name are printed.
If a title matches multiple files, an error is raised.
@taikedz
taikedz / lizard_complexity.py
Last active September 3, 2021 09:04
Wrap lizard's CSV complexity output in a usable object, and give usage example
import sys
from collections import namedtuple
# A friendlier named object for working with each output line
Analysis = namedtuple("Analysis", [
"NLOC", # Count of number of active LOC (excl whitespace)
"CCN", # Cyclomatic Complexity Number
"token", # token count: how many syntactic tokens ("if", "[", "5", etc) are used in the functions
"PARAM", # number of parameters to the function
@taikedz
taikedz / README.md
Last active March 26, 2021 12:17
Get the sample frequency on a loop call to `time.time()`

Time Sampling

I was curious to know what level of precision I could get when using time.sleep(x), like, if it made any sense to try and sleep for say 0.0132 seconds.

It turns out, it does. On a Windows machine with a 1.6GHz processor, I get a sample rate such:

$ python3 time_sampling.py 6
Average step over 1000000 (100.0%) iterations: 2.77e-07