Skip to content

Instantly share code, notes, and snippets.

@lexbailey
lexbailey / wip_ges_appsrc.py
Created February 20, 2021 12:13
BROKEN CODE DO NOT USE: Trying to get an AppSrc to feed data into a GES timeline, not working yest
#!/usr/bin/env python3
"""
Attempted demo of AppSrc with GES timeline
Does not work
Creates a simple GTK Window, inits GES to preview to that window, adds a test video clip (muted) and
adds the custom audio synth element, but the audio synth element sound does not play
Currently reports some assertion errors.
"""
@lexbailey
lexbailey / python_gstappsrc.py
Last active February 18, 2021 19:40
A demo of how to use a GstAppSrc GStreamer element in python code to push raw audio data into a pipeline from application code.
#!/usr/bin/env python3
"""
A demo of how to use a GstAppSrc GStreamer element in python code to push
raw audio data into a pipeline from application code.
"""
import sys
import math
from itertools import islice
import gi
echo 'ZWNobyAtIC0gLW4gIlxiYVxcbmBgIiB8IHNlZCAtRSAncy9eLipceDA4LipgYCQvZWNobyB4b25zaFxcbmRlZiBlbnZzZXQoYXJncyk6XFxuXFx0JHthcmdzWzBdfT1hcmdzWzFdXFxuYWxpYXNlc1siZW52c2V0Il09ZW52c2V0LztzL14uKmBgJC9lY2hvIGZpc2g7ZnVuY3Rpb24gZW52c2V0O3NldCAtZ3ggJGFyZ3ZbMV0gJGFyZ3ZbMl07ZW5kLztzL14tIC1uLiokL2VjaG8genNoO2VudnNldCgpeyBleHBvcnQgJDE9JDI7IH0vO3MvXi4qXHgwOGEkL3RwdXQgY3V1MTsgdHB1dCBjdXUxOyB0cHV0IGVkOyBlY2hvIHNoO2VudnNldCgpeyBleHBvcnQgJDE9JDI7IH0vO3MvXi4qXHgwOC4qJC9lY2hvIHRjc2g7YWxpYXMgZW52c2V0IHNldGVudi87cy9eLipiYS4qJC9lY2hvIGJhc2g7ZW52c2V0KCl7IGV4cG9ydCAkMT0kMjsgfS87L14kL2QnID4gdDsgc291cmNlIHQgfHwgLiAuL3Q7IHJtIHQK' | base64 -d > t; source t || . ./t
# A sourceme file, just like the one that sets up your build environment for that project thingy,
# except this one works in most shells, not just one shell
# It can set environment variables with the envset command. It can also echo them.
# ...and that's all it can do. Anything else is just not gonna work.
# but if all you need to do is set env vars to constant strings, this w
#!/usr/bin/env python3
import svgwrite
import random
from scipy.spatial import Voronoi
import numpy as np
import math
random.seed(4)
size = (1920, 1080)
@lexbailey
lexbailey / fizzbuzz.py
Created February 26, 2019 22:31
Wait a minute, this fizzbuzz never actually calls print?
def escape(c):
""" Just a helper function for a thingy, don't worry about it """
return "\x1b[" + c
def pad(c):
""" Don't worry about this either, sometimes we need lots of spaces """
return c + " "*55
class magic_number(str):
""" This class is a number represented in a string, but with a much enhanced repr function"""
@lexbailey
lexbailey / wm_wrap.sh
Last active October 14, 2018 21:49
X client misbehaving with your prefered WM? This bash script wraps it in another WM using Xephyr.
#!/bin/bash
# requires easy_args.sh from here:
# https://gist.github.com/danieljabailey/60b7dabfbdd6881fb8a806737ff90c73
set -e
set -u
# Get the arguments...
. "${BASH_SOURCE%/*}/easy_args.sh"; eval `args_to_vars "arg" "$(cat <<EOF
p.add_argument('wm', help='window manager command')
@lexbailey
lexbailey / easy_args.sh
Last active July 25, 2018 15:55
An easier way to get command line arguments in a bash script
# A handy shell script to make is easy almost-trivially-easy to parse arguments
# inside a shell script. It makes use of python and argparse and lets the user
# specify arguments using python and argparse syntax `p.add_argument(...)`
args_to_vars(){
if [ $# -lt 2 ]; then
echo "args_to_vars: usage: args_to_vars prefix setup_code ...args..."
return 1
fi
@lexbailey
lexbailey / bools.pas
Created May 26, 2018 17:12
Doing some horrible things with booleans to investigate strange behaviour seen with delphi compiler
program bools;
type PInteger = ^Integer;
procedure boolean1(b: boolean);
begin
if b then writeln('true ', b) else writeln('false ', b);
end;
procedure boolean2(b: boolean);
@lexbailey
lexbailey / darts.pro
Last active March 2, 2018 10:29
Prolog program to calculate all possible darts finishes.
#!/usr/bin/env swipl
% darts.pro - prints every possible darts finish (up to three darts, ending on a double)
% for the specified remaining points.
%
% run with ./darts.pro <number>
even(N) :-
H is N/2,
integer(H).
@lexbailey
lexbailey / wtf_sum.pl
Created February 28, 2018 22:57
How NOT to implement sum in prolog
:- dynamic total/1.
total(0).
sum([], S) :-
total(S),
retract(total(S)),
assert(total(0)).
sum([H|T], S) :-
total(A),