Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Nuttall bennuttall

View GitHub Profile
View mosgit.py
from mosromgr.mostypes import MosFile
from glob import glob
from git import Repo
files = glob('*.mos.xml')
ro, *mosfiles = sorted(MosFile.from_file(f) for f in files)
repo = Repo.init('.')
ro_id = ro.ro_id.replace(';', '_')
View fixup.sh
for f in */*LOG*.csv; do
tr < $f -d '\000' > $f.tmp
mv $f.tmp $f
done
@bennuttall
bennuttall / .htaccess
Created May 23, 2020
wordpress dev .htaccess
View .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wp-content/uploads/(.*)$ https://bennuttall.com/wp-content/uploads/$1 [L,R=302]
</IfModule>
View main.md

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:

...
View explorerzero.py
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)
View test.py
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:
View README.md

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?

View color.py
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)
View words.py
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())
View w1.py
import warnings
class MyWarning(Warning):
pass
warnings.warn(
'this '
'is '
'a '
'warning',