Skip to content

Instantly share code, notes, and snippets.

View howardjones's full-sized avatar

Howard Jones howardjones

  • United Kingdom
View GitHub Profile
@howardjones
howardjones / extract.py
Last active November 16, 2021 21:41
extract the cura settings from a gcode file
import json
import ast
from codecs import encode, decode
with open("CFFFP_Drawer_ThinHandle_TOLERANT.gcode", "r", encoding="utf-8") as f:
settings_lines = [
line.strip()[11:] for line in f.readlines() if line.startswith(";SETTING_3 ")
]
data = json.loads("".join(settings_lines))
@howardjones
howardjones / README.md
Last active February 12, 2021 08:45
Python Directory iterator

DirectoryIterator

simple iterator for walking directory trees, optionally returning only matching files

e.g.

def is_json(filename):
    return filename.endswith(".json")

starts = ['X:\\configs', 'X:\\todo']

d = DirectoryIterator(starts, is_json)

@howardjones
howardjones / cache-but-not-images.py
Created September 18, 2020 07:43
So you have a crawler, but you don't want it to cache images, just the page.
from cachecontrol import CacheControl
from cachecontrol.caches import FileCache
from cachecontrol.heuristics import BaseHeuristic
class NoImagesHeuristic(BaseHeuristic):
def update_headers(self, response):
if response.headers['Content-Type'].startswith("image/"):
return {
'cache-control': 'no-cache',
}
@howardjones
howardjones / dformat
Created November 30, 2019 09:27
Reformatted copy of DFORMAT, a troff preprocessor for representing data formats. See https://lists.gnu.org/archive/html/groff/2012-11/pdfRiXK_KnNhU.pdf
#!/usr/bin/awk -f
# mailto:jlb@research.bell-labs.com
function error(s)
{
print "dformat error: " s " near input line " NR | "cat 1>&2";
}
BEGIN {
s= "recht 0.3 addrht 0.055 recspread 0.15 ";
@howardjones
howardjones / MapLoader.cs
Last active July 19, 2019 11:40
A Unity 5 script to load a ZX Spectrum snapshot file of Sandy White's Ant Attack 3D, extract the map, and create it in the current scene. The ANTATTAK resource is a SNA file imported into Unity. 'floor' is a GameObject for each 1x1x1 cube, textured with a stone texture. The loader creates clones of this.
using UnityEngine;
using System.Collections;
public class MapLoader : MonoBehaviour
{
public GameObject floor;
bool IsBitSet (byte b, int pos)
@howardjones
howardjones / gist:11eabfb9ea1497a9d6b64368bda80059
Created May 30, 2019 19:51
Allow intra-zone traffic with firewalld
#!/bin/sh
interfaces=$(firewall-cmd --info-zone=internal | grep interfaces | cut -d' ' -f 4-)
for a in $interfaces; do
for b in $interfaces; do
if [ $a != $b ]; then
echo "$a to $b"
firewall-cmd --permanent --direct --add-rule ipv4 filter FWDI_internal_allow 0 -o $a -i $b -j ACCEPT
# missing all the `exit`s
scope eth-uplink
create vlan VLAN-20 20
commit-buffer
scope org /
create org USER-POD-2
commit-buffer
controls:
- children:
- commands:
- G12 P1 S4
name: Clean
type: command
- commands:
- G27
name: Park
type: command
@howardjones
howardjones / postbuild.js
Last active January 17, 2018 11:26 — forked from bfocht/postbuild.js
post build script for create-react-app to move the js to a dist folder
// Taken almost verbatim from https://gist.github.com/bfocht/a0def4432d0f93dc28bc7cf64ebe8be1
// copy the just-built js code into the place weathermap/cacti expect to find it
const fs = require('fs');
const src = './build/';
const dest = '../../cacti-resources/user/';
const targets = ["main.js", "main.css"];
#!/usr/bin/perl
# Cheezy perl script to produce the typeset Unix manual, as ken intended.
#
# Gets a list of every manpage from man(1), and compile them into per-section PDF files in the final/ subdir
# Pulls the intro page to the front of each section, if there is one.
# Also leaves the individual PDF pages in the various man* subdirs
#
# Assumptions: you have groff and ghostscript installed. I think you will need to run makewhatis, too.
#