Skip to content

Instantly share code, notes, and snippets.

@ali1234
ali1234 / input.py
Last active December 24, 2022 00:54
Unbuffered, non-blocking stdin in Python
import fcntl
import termios
import sys
import os
import time
class NonBlockingInput(object):
def __enter__(self):
@ali1234
ali1234 / icon.py
Created April 25, 2018 20:46
Find the path Gtk loads an icon from.
#!/usr/bin/env python3
import sys
import pathlib
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
if __name__ == '__main__':
@ali1234
ali1234 / life.py
Created March 11, 2018 01:04
PySDL2 Life Demo
import sys
import sdl2
import sdl2.ext
import numpy as np
class Life(object):
def __init__(self, height, width):
self.width = width
@ali1234
ali1234 / clock.py
Created March 2, 2018 14:54
scroll phat hd clock
#!/usr/bin/env python
import time
import signal
import math
import scrollphathd
from envirophat import light, motion, weather
"""
@ali1234
ali1234 / devices.py
Last active March 4, 2018 19:54
Unified Graphics Library Yarrrrrrr
import subprocess, time, sys
import numpy as np
from PIL import Image
class GraphicsDeviceBase(object):
def __init__(self, buf, depth):
self.__buf = buf
#!/usr/bin/env python
import unicornhathd
import datetime
import numpy as np
print("""Unicorn HAT HD: Rainbow
OMG MY EYES.
Press Ctrl+C to exit!
@ali1234
ali1234 / switchingdemo.py
Created February 26, 2018 00:11
unicorn hat hd demos
import time, math, colorsys, random
from datetime import datetime, timedelta
from picamera import PiCamera
import numpy as np
import unicornhathd
unicornhathd.rotation(270)
.SUFFIXES: .pov .png
FINAL_IMAGES=block-bg-all.png block-spec-all.png block-spec-ext.png block-mask-inverted.png
PREVIEW_IMAGES=block-preview-render.png
TEMP_IMAGES=block-mask-inverted.png
TS=128
all: $(FINAL_IMAGES) preview
dist: $(FINAL_IMAGES) dist-clean
@ali1234
ali1234 / aiyprojects-ubuntu.txt
Last active July 4, 2018 07:30
How to run the google aiyprojects voice kit code on Ubuntu desktop.
# set up a python virtualenv:
virtualenv --system-site-packages -p python3 google-assistant-sdk
# enter the virtualenv:
source google-assistant-sdk/bin/activate
# install dependencies:
pip3 install google-assistant-sdk[auth_helpers]==0.1.0 grpc-google-cloud-speech-v1beta1==0.14.0 protobuf==3.1.0
# the google code actually works out of the box on a default ubuntu install:
@ali1234
ali1234 / colourswap.py
Last active March 29, 2017 23:25
Rebrickable API tool to find colour replacements
#!/usr/bin/env python
# Finds colour replacements for an LDraw file.
# Usage:
# colourswap.py <LDraw file> <colour> [<rarity>]
# colour: an LDraw colour number, eg yellow = 14
# rarity: pieces must be in at least this many sets