Skip to content

Instantly share code, notes, and snippets.

View bennuttall's full-sized avatar

Ben Nuttall bennuttall

View GitHub Profile

Installing some pip packages globally, on a Raspberry Pi that's netbooted. Its root filesystem is on an NFS share.

root@piwheels20:# pip3 install pypandoc versioneer kervi scikit-build cython

Packages are collected and prepared for installation, and then it errors while trying to uninstall the system-installed cryptography:

...
from gpiozero import LEDBoard, Motor
class ExplorerHat:
def __init__(self, pwm=False):
self.leds = LEDBoard(blue=4, yellow=17, red=27, green=5,
_order=('blue', 'yellow', 'red', 'green'),
pwm=pwm
)
self.motor_1 = Motor(forward=20, backward=19)
self.motor_2 = Motor(forward=26, backward=21)
import sys
def foo(n):
n = int(n)
for i in range(n):
print(i + 1)
if len(sys.argv) > 1:
foo(sys.argv[1])
else:

word chain challenge

Given a wordlist (say, the English dictionary), if you can remove a letter from a word and the new word is a known word (in the wordlist), this makes a chain of length 2. If you can repeat this for a second time, you continue to the third level, and so on.

For example, the word "trees" has a chain length of 3:

Using the system dictionary (code snippet provided), how long is the longest chain? And which words make the longest chain?

from tree import Tree
from colorzero import Color
tree = Tree(25, mosi_pin=12, clock_pin=25)
while True:
try:
txt = input('Enter a colour name: ')
c = Color(txt)
print(c)
import operator
from graphviz import Digraph
alphabet = 'qwertyuiopasdfghjklzxcvbnm'
with open('/usr/share/dict/british-english') as f:
WORDS = {
word.strip()
for word in f
if all(c in alphabet for c in word.strip())
import warnings
class MyWarning(Warning):
pass
warnings.warn(
'this '
'is '
'a '
'warning',
@bennuttall
bennuttall / btn.py
Last active September 18, 2019 10:56
from gpiozero import Button
from gpiozero.tools import all_values, any_values
class MyButton(Button):
def __and__(self, other):
return all_values(self, other)
def __or__(self, other):
return any_values(self, other)
from github import Github
from time import sleep
token = '' # enter your github access token
def is_language(path):
# a function to determine whether or not a path from a git tree is a language folder
# must be a "tree" (a folder) rather than a file
# must be 5 characters long with a hyphen in the middle e.g. "fr-CA"
return item.type == 'tree' and len(path) == 5 and path[2] == '-'
# this is the old version, only use if you have issues with the short version
mkdir wheels
cd wheels
wget https://bennuttall.com/files/37wheels/Keras_Applications-1.0.8-py3-none-any.whl
wget https://bennuttall.com/files/37wheels/Keras_Preprocessing-1.1.0-py2.py3-none-any.whl
wget https://bennuttall.com/files/37wheels/Markdown-3.1.1-py2.py3-none-any.whl
wget https://bennuttall.com/files/37wheels/Werkzeug-0.15.4-py2.py3-none-any.whl
wget https://bennuttall.com/files/37wheels/absl_py-0.7.1-cp37-none-any.whl
wget https://bennuttall.com/files/37wheels/astor-0.8.0-py2.py3-none-any.whl