Skip to content

Instantly share code, notes, and snippets.

Avatar

Tai Kedzierski taikedz

View GitHub Profile
View README.md

This is a demo

  • Some markdown
@taikedz
taikedz / README.md
Last active Mar 26, 2021
Get the sample frequency on a loop call to `time.time()`
View README.md

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
@taikedz
taikedz / README.md
Last active Dec 9, 2020
ShellPipe.py - use shell-like piping mechanisms.
@taikedz
taikedz / README.md
Created Oct 14, 2020
Convert YAML data to Python
View README.md

Quick one-off script to convert a yaml file to native python.

python3 convert-yaml-to-python.py YAMLFILE > my_data.py

A little naive, but a quick tool otherwise.

@taikedz
taikedz / deepyaml.py
Last active Sep 10, 2020
Load a YAML file with references to other YAML files
View deepyaml.py
import yaml
import os
class RecursiveYamlLoad(Exception):
pass
def mingw_path(path):
#TODO not yet finished
""" Running Python in MinGW (incl Git Bash) causes abspath() to mangle the path
@taikedz
taikedz / README.md
Created Aug 28, 2020
Windows things to install
View README.md

Windows things to install

New workflow for setting up a new Windows machine:

  1. Set up chocolatey https://chocolatey.org/install
  2. Use choco install for everything

Package list:

@taikedz
taikedz / README.md
Created Aug 28, 2020
Run Linux X apps on Windows
View README.md

Run X apps on Windows

Two methods - either through WSL, or through SSH with cygwin/git bash/mingw.

Both require an X server

Easiest so far to install is VcXsrv through chocolatey

  1. Install chocolatey https://chocolatey.org/install
  2. Install vcxsrv: choco install vcxsrv -y
@taikedz
taikedz / README.md
Last active May 10, 2021
Bitstrings converter
View README.md

Bitstrings converter

Probably many people have written something like this, for converting those joke images purporting to contain L3E7 h4xx0R c0deZ.

Data examples:

  • ascii-bits.txt: taken from a random pic of a mini typewriter with a 1 and 0 keyboard.
  • message.txt: taken from a music video ad with an AI-type character

Script:

@taikedz
taikedz / README.md
Created Jul 4, 2019
Controlled runner and argument parser
View README.md

A pair of python3 scripts for importing. I wrote these to facilitate writing wrappers external commands, when replacing some shell scripts. There might be better ways to do it (including checking for libraries in lieu of commands) but in absence of that possibility (looking at you, docker-compose!), these have made things much easier...!

The arguments.py script allows loading a parser with some defaults, as well as passing your own argparse definitions to it. It then returns a usable dicitonary in which to look up items.

The runner.sh script provides a convenience set of functions for runnning external commands, as well as a dry run mode predicated on use of --dry-run from the arguments.sh script. It also accepts a simple dict mapping extra environment variables into the existing environment

Example

import runner
@taikedz
taikedz / README.md
Last active Jul 4, 2019
Query JSON and nested dicts/lists easily
View README.md

This is a relatively simple JSON object traverser: feed it either a JSON string or a nested set of dicitonaries/lists and use a path notation to access individual items.

  • It supports paths separated with either / or any separator string you specify
  • It supports wildcards * to iterate over multiple values
  • Arrays/lists are accessed simply by number instaed of names e.g. name_with_array/0/property_of_zeroth_item
  • If a bad query token or data type is encountered, it will print the offending path

It is relatively naive, insomuch as it will create a new array in the output object for each wildcard used along the path. For example, here's an example of getting all subnet definitions on docker inspect <networks ...>: