Skip to content

Instantly share code, notes, and snippets.

@SamDudley
SamDudley / script-template.py
Created March 13, 2024 15:57
A python script template with no dependencies.
#!/usr/bin/env python3
import argparse
class CommandError(Exception):
pass
def main(args):
@SamDudley
SamDudley / highlight-text.js
Created July 13, 2023 10:42
A web component which highlights text against a pattern.
(function () {
const template = document.createElement("template");
template.innerHTML = `
<style>
span span {
background: yellow;
}
</style>
<span></span>
@SamDudley
SamDudley / check-requirements.sh
Created April 23, 2023 17:24
Check requirements.txt is up to date with Poetry export.
# `poetry export --without-hashes` output requirements to stdout
# `--without-hashes` is optional
# `git diff --exit-code -- requirements.txt -`
# `--exit-code` exit with 1 if there is a difference
# `requirements.txt -` diff the requirements file with stdin (output from poetry export)
poetry export --without-hashes | git diff --exit-code -- requirements.txt -
@SamDudley
SamDudley / cli-script.py
Created April 19, 2023 13:55
A Python CLI script template using argparse to handle arguments.
#!/usr/bin/env python3
import argparse
def main(args):
print(args.foo)
if __name__ == "__main__":

Bash

# Generate 8 random characters.
cat /proc/sys/kernel/random/uuid | cut -c 1-8

Python

How isinstance works

@SamDudley
SamDudley / work-environment.md
Last active January 31, 2021 17:30
Work environment

Work environment

Tools

  • docker
  • docker-compose
  • peek
  • flameshot
@SamDudley
SamDudley / useful-commands.sh
Created December 15, 2020 09:30
Useful commands
sudo nmap -sn 192.168.1.0/24 | rg -B 2 Dell
@SamDudley
SamDudley / hideIndeedSponseredResults.js
Last active January 21, 2018 16:59
Hides all the sponsered job search results shown by indeed.
function hideAllSponseredResults() {
// A little helper function to convert node lists returned from querySelector
// to a proper array so we can use methods like filter.
function toArray(nodeList) {
let array = []
nodeList.forEach(node => array.push(node))
return array
}
// Find all the results.
@SamDudley
SamDudley / trelloBoardToText.js
Last active July 23, 2019 02:19
Alerts a markdown like text version of trello board's lists and cards.
// Helper function to convert node lists returned by querySelectorAll to an array
// so that we can used methods like map and filter.
function toArray(nodeList) {
let array = []
nodeList.forEach(node => array.push(node))
return array
}
// Returns a text (like markdown) representation of a trello board.
function trelloBoardAsText() {