Skip to content

Instantly share code, notes, and snippets.

@k12ish
k12ish / knights_move_sympy.py
Last active December 16, 2023 10:00
Knights Move Puzzle (with Sympy!!)
from sympy import symbols, solve, Eq
def knight_moves(x, y, board_size=8):
moves = [
(x + 1, y + 2),
(x + 1, y - 2),
(x - 1, y + 2),
(x - 1, y - 2),
(x + 2, y + 1),
@k12ish
k12ish / .gitignore
Last active August 1, 2023 14:51
Python Boilerplate
#### --- Python.gitignore from github.com/github/gitignore ---
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
@k12ish
k12ish / IntegratedDesignProject.ino
Created November 6, 2022 14:01
Autonomous Vehicle Project as part of CUED IB coursework
#include <Adafruit_MotorShield.h>
#include <BlockNot.h>
#include <math.h>
// Pin IO
const int pinLineSensor1 = A0;
const int pinLineSensor2 = A1;
const int pinLineSensor3 = A2;
@k12ish
k12ish / supervision.py
Last active January 23, 2023 09:34
Script to generate supervision timetable
from ics import Calendar, Event
from datetime import datetime, timedelta
# init the calendar
cal = Calendar()
def new(topic, weeks, days):
for week in [timedelta(days=w*7) for w in weeks]:
event = Event()
event.name = topic + ' Supo'
@k12ish
k12ish / pdf_resizer.sh
Created September 15, 2022 18:34
Simple script that resizes PDF files to A4
DIRECTORY=.
for FILEPATH in $DIRECTORY/PDF-*.pdf; do
FILENAME="$(basename "$FILEPATH" .pdf)_A4"
pdftocairo -pdf -paper A4 $FILEPATH processed/$FILENAME.pdf
mv $FILEPATH processed/
done
@k12ish
k12ish / logging_boilerplate.py
Created August 25, 2022 10:42
Python Logging Boilerplate
import logging
from logging.handlers import RotatingFileHandler
file_handler = RotatingFileHandler("my_log.log", backupCount=5)
file_handler.doRollover()
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script src="https://rawgit.com/jasondavies/d3-cloud/master/build/d3.layout.cloud.js"></script>
<script>
//Based on https://github.com/jasondavies/d3-cloud/blob/master/examples/simple.html
// Encapsulate the word cloud functionality
@k12ish
k12ish / substring_index.rs
Created July 15, 2021 21:31
Find the byte index of substrings, unambiguously.
use core::ops::Range;
fn main() {
let quote = String::from("I scream, you scream, we all scream for ice cream");
assert_eq!(&quote[2..8], "scream");
assert_eq!(&quote[14..20], "scream");
assert_eq!(&quote[29..35], "scream");
// substring_index(&quote, "scream")
assert_eq!(substring_index(&quote, &quote[2..8]), 2..8);
@k12ish
k12ish / LectureCondenser.jl
Last active December 23, 2021 08:11
Select images from slideshow with maximum amount of text.
### A Pluto.jl notebook ###
# v0.12.18
using Markdown
using InteractiveUtils
# ╔═╡ 04587fae-597f-11eb-03db-41e2e288cabc
using VideoIO, ImageFiltering, Images, Plots
# ╔═╡ a522894e-59b5-11eb-147f-71052ad6df32