Skip to content

Instantly share code, notes, and snippets.

@PMaynard
PMaynard / disk-gob.go
Last active September 4, 2023 09:10
Go serialise data to disk using encoding/gob.
/*
* Author: Peter Maynard (pete[at]port22[co/uk])
* Date: 2023 September 04
* Summary:
* Serialises a structure and writes to disk as a file.
* The data can be read back in and accessed as a normal
* struct.
*
* The data stored on disk is plain text so be careful
* where you store it
# Copyright 2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
PYTHON_COMPAT=( python2_7 python3_5 python3_6 python3_7 )
inherit distutils-r1
DESCRIPTION="Reference homeserver for the Matrix decentralised comms protocol"
@PMaynard
PMaynard / fancy.log
Created December 3, 2016 14:10
AddressSanitizer
$ sudo !!
sudo ./laf
[sudo] password for osaka:
[>] Allowing traffic to 443
from *
[>] Allowing traffic to 80
from *
[>] Allowing traffic to *
from 127.0.1.1
[>] Allowing traffic to *
@PMaynard
PMaynard / zorg.py
Created April 21, 2016 13:27
Last.fm youtube downloader
#!/usr/bin/python
# pip install --upgrade google-api-python-client
import urllib2
import json
import time
import subprocess
from apiclient.discovery import build
from apiclient.errors import HttpError
@PMaynard
PMaynard / gist:ec7c634d37dc19dd8e45b9755d5f26e0
Created April 20, 2016 15:26
pandoc markdown to latex to pdf
pandoc --toc \
--toc-depth=4 \
--bibliography=../MyLibrary.bib \ #bittext file
--filter pandoc-citeproc \
--csl=ieee.csl \ # referrence format
--number-sections \
--template style/template.tex \ # latex template optional
-V documentclass=report \
-V papersize=a4paper \
-V fontsize=12pt \
@PMaynard
PMaynard / tracker.sh
Last active April 4, 2016 13:55
Trackers word, line, byte size, and char count. cron this to run, chart the output.
#!/bin/bash
FILE="file.md"
COUNT=$(wc -w -l -c -m "$FILE" | tr -s ' ' | sed 's/^//' | sed 's/ /,/g' | cut -b 2- )
DATETIME=$(date +%Y-%m-%d-%H-%M)
echo $COUNT,$DATETIME >> "tracker.csv"
@PMaynard
PMaynard / convert-to-gml.py
Last active March 22, 2016 14:26
Convert tab indented to GML graph
#!/bin/python
## sudo apt-get install python-networkx python-pydot
# Converts from tab indented lines to graph modelling language (GML)
# Example indented lines:
#
# Duqu 2.0 : SAND
# Spear-phishing : SAND
# Exploit CVE-2014-4148 : SAND
# Target downloads and opens word document : SAND
#! /bin/sh
### BEGIN INIT INFO
# Provides: xmpp-443
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: socat port forward 443 -> 5222
# Description: Forwards data from port 443 to port 5222 using socat.
### END INIT INFO
@PMaynard
PMaynard / screen.sh
Created May 14, 2015 15:15
Insert commands to a screened session.
# Create a screened bash instance.
screen -S term01 bash
# Open a new terminal window and send the command 'ls\n' - the newline runs the command.
screen -S term01 -p 0 -X stuff "ls\n"
# -S <name> is the screen name
# -p 0 - tells it to use the first window, there can be more than one. (Default one)
# -X stuff '<cmd>' - Send the specified command to a running screen session.
@PMaynard
PMaynard / pdml-csv.py
Last active August 29, 2015 14:19
PDML to CSV
from lxml import etree
import csv, argparse
def readData(data_file, listop=False):
if listop:
data = []
else:
data = set()
with open(data_file, 'rb') as f:
reader = csv.reader(f)