Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Nuttall bennuttall

View GitHub Profile
@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',
View btn.py
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)
View languages.py
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] == '-'
You can’t perform that action at this time.